mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
offers
This commit is contained in:
parent
1c58cb060e
commit
194039cd1a
4 changed files with 61 additions and 3 deletions
|
@ -7,6 +7,11 @@ module FbGraph2
|
|||
Offer.new(offer[:id], offer).authenticate self.access_token
|
||||
end
|
||||
end
|
||||
|
||||
def offer!(params = {})
|
||||
offer = self.post params, edge: :offers
|
||||
Offer.new(offer[:id], params.merge(offer)).authenticate self.access_token
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +1,8 @@
|
|||
module FbGraph2
|
||||
class Offer < Node
|
||||
register_attributes(
|
||||
raw: [:claim_limit, :coupon_type, :image_url, :published, :redemption_code, :redemption_link, :terms, :title, :message],
|
||||
time: [:created_time, :expiration_time, :reminder_time],
|
||||
timestamp: [:scheduled_publish_time],
|
||||
raw: [:claim_limit, :coupon_type, :image_url, :redemption_code, :redemption_link, :terms, :title, :message],
|
||||
time: [:created_time, :expiration_time],
|
||||
page: [:from]
|
||||
)
|
||||
end
|
||||
|
|
35
spec/fb_graph2/edge/offers_spec.rb
Normal file
35
spec/fb_graph2/edge/offers_spec.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FbGraph2::Edge::Offers do
|
||||
context 'included in Page' do
|
||||
let(:page) { FbGraph2::Page.new('page_id').authenticate('page_token') }
|
||||
|
||||
describe '#offers' do
|
||||
it 'should return an Array of FbGraph2::Offer' do
|
||||
offers = mock_graph :get, 'page_id/offers', 'page/offers', access_token: 'page_token' do
|
||||
page.offers
|
||||
end
|
||||
offers.should be_instance_of FbGraph2::Edge
|
||||
offers.should_not be_blank
|
||||
offers.each do |offer|
|
||||
offer.should be_instance_of FbGraph2::Offer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#offer!' do
|
||||
it 'should return FbGraph2::Offer' do
|
||||
offer = mock_graph :post, 'page_id/offers', 'success_with_id', access_token: 'page_token', params: {
|
||||
title: 'Foobar',
|
||||
expiration_time: 10.days.from_now.to_s
|
||||
} do
|
||||
page.offer!(
|
||||
title: 'Foobar',
|
||||
expiration_time: 10.days.from_now
|
||||
)
|
||||
end
|
||||
offer.should be_instance_of FbGraph2::Offer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
spec/mock_json/page/offers.json
Normal file
19
spec/mock_json/page/offers.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"data": [{
|
||||
"id": "797106500309744",
|
||||
"from": {
|
||||
"category": "Software",
|
||||
"name": "FbGraph",
|
||||
"id": "117513961602338"
|
||||
},
|
||||
"title": "Foobar",
|
||||
"created_time": "2014-09-02T09:56:14+0000",
|
||||
"expiration_time": "2014-09-12T14:59:59+0000",
|
||||
"image_url": "https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xap1\/v\/t1.0-1\/p200x200\/12758_485082394845491_483124061_n.png?oh=ffdf2fc204852be4167eebaeb7f1b2ec&oe=54733980&__gda__=1415926027_bbf6edaad90b94e23268131e6d8f258b",
|
||||
"claim_limit": 1000000000,
|
||||
"coupon_type": "in_store_only"
|
||||
}],
|
||||
"paging": {
|
||||
"next": "https:\/\/graph.facebook.com\/v2.0\/117513961602338\/offers?limit=50&offset=50&__after_id=enc_Aey48t-R5OQbq6nWOeyBEJKEHiddR7mdWX_5Pg0nBoVbmDoe_Lr4d_5XIg4vhahIQ7oFJzHsY8P91oMo_GD_ZrNy"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue