gs_graph 2.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitattributes +22 -0
- data/.gitignore +26 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +95 -0
- data/LICENSE +20 -0
- data/README.rdoc +314 -0
- data/Rakefile +25 -0
- data/VERSION +1 -0
- data/assets/fb_graph.ai +1726 -6
- data/assets/fb_graph.png +0 -0
- data/gs_graph.gemspec +28 -0
- data/lib/gs_graph.rb +174 -0
- data/lib/gs_graph/achievement.rb +44 -0
- data/lib/gs_graph/action.rb +12 -0
- data/lib/gs_graph/ad_account.rb +51 -0
- data/lib/gs_graph/ad_campaign.rb +39 -0
- data/lib/gs_graph/ad_campaign_stat.rb +22 -0
- data/lib/gs_graph/ad_connection_object.rb +53 -0
- data/lib/gs_graph/ad_creative.rb +44 -0
- data/lib/gs_graph/ad_group.rb +51 -0
- data/lib/gs_graph/ad_group_stat.rb +22 -0
- data/lib/gs_graph/ad_keyword.rb +20 -0
- data/lib/gs_graph/ad_keyword_suggestion.rb +8 -0
- data/lib/gs_graph/ad_keyword_valid.rb +23 -0
- data/lib/gs_graph/ad_preview.rb +10 -0
- data/lib/gs_graph/ad_user.rb +58 -0
- data/lib/gs_graph/age_range.rb +12 -0
- data/lib/gs_graph/album.rb +59 -0
- data/lib/gs_graph/app_request.rb +24 -0
- data/lib/gs_graph/application.rb +119 -0
- data/lib/gs_graph/auth.rb +88 -0
- data/lib/gs_graph/auth/cookie.rb +20 -0
- data/lib/gs_graph/auth/signed_request.rb +44 -0
- data/lib/gs_graph/broad_targeting_category.rb +13 -0
- data/lib/gs_graph/checkin.rb +51 -0
- data/lib/gs_graph/collection.rb +55 -0
- data/lib/gs_graph/comment.rb +24 -0
- data/lib/gs_graph/comparison.rb +13 -0
- data/lib/gs_graph/connection.rb +37 -0
- data/lib/gs_graph/connections.rb +3 -0
- data/lib/gs_graph/connections/accounts.rb +23 -0
- data/lib/gs_graph/connections/achievements.rb +21 -0
- data/lib/gs_graph/connections/activities.rb +14 -0
- data/lib/gs_graph/connections/ad_accounts.rb +15 -0
- data/lib/gs_graph/connections/ad_campaign_stats.rb +22 -0
- data/lib/gs_graph/connections/ad_campaigns.rb +30 -0
- data/lib/gs_graph/connections/ad_connection_objects.rb +14 -0
- data/lib/gs_graph/connections/ad_creatives.rb +14 -0
- data/lib/gs_graph/connections/ad_group_stats.rb +22 -0
- data/lib/gs_graph/connections/ad_groups.rb +35 -0
- data/lib/gs_graph/connections/ad_previews.rb +10 -0
- data/lib/gs_graph/connections/admins.rb +10 -0
- data/lib/gs_graph/connections/albums.rb +21 -0
- data/lib/gs_graph/connections/app_notifications.rb +10 -0
- data/lib/gs_graph/connections/app_requests.rb +21 -0
- data/lib/gs_graph/connections/attending.rb +26 -0
- data/lib/gs_graph/connections/banned.rb +31 -0
- data/lib/gs_graph/connections/blocked.rb +36 -0
- data/lib/gs_graph/connections/books.rb +14 -0
- data/lib/gs_graph/connections/broad_targeting_categories.rb +14 -0
- data/lib/gs_graph/connections/checkins.rb +21 -0
- data/lib/gs_graph/connections/comments.rb +21 -0
- data/lib/gs_graph/connections/conversations.rb +14 -0
- data/lib/gs_graph/connections/declined.rb +25 -0
- data/lib/gs_graph/connections/docs.rb +14 -0
- data/lib/gs_graph/connections/events.rb +21 -0
- data/lib/gs_graph/connections/family.rb +14 -0
- data/lib/gs_graph/connections/feed.rb +21 -0
- data/lib/gs_graph/connections/former_participants.rb +14 -0
- data/lib/gs_graph/connections/friend_lists.rb +21 -0
- data/lib/gs_graph/connections/friend_requests.rb +12 -0
- data/lib/gs_graph/connections/friends.rb +14 -0
- data/lib/gs_graph/connections/games.rb +14 -0
- data/lib/gs_graph/connections/groups.rb +14 -0
- data/lib/gs_graph/connections/home.rb +14 -0
- data/lib/gs_graph/connections/inbox.rb +20 -0
- data/lib/gs_graph/connections/insights.rb +27 -0
- data/lib/gs_graph/connections/interests.rb +14 -0
- data/lib/gs_graph/connections/invited.rb +36 -0
- data/lib/gs_graph/connections/likes.rb +29 -0
- data/lib/gs_graph/connections/links.rb +21 -0
- data/lib/gs_graph/connections/maybe.rb +25 -0
- data/lib/gs_graph/connections/members.rb +22 -0
- data/lib/gs_graph/connections/messages.rb +22 -0
- data/lib/gs_graph/connections/milestones.rb +21 -0
- data/lib/gs_graph/connections/movies.rb +14 -0
- data/lib/gs_graph/connections/music.rb +14 -0
- data/lib/gs_graph/connections/mutual_friends.rb +26 -0
- data/lib/gs_graph/connections/noreply.rb +23 -0
- data/lib/gs_graph/connections/notes.rb +21 -0
- data/lib/gs_graph/connections/notifications.rb +18 -0
- data/lib/gs_graph/connections/offers.rb +22 -0
- data/lib/gs_graph/connections/outbox.rb +20 -0
- data/lib/gs_graph/connections/participants.rb +14 -0
- data/lib/gs_graph/connections/payments.rb +14 -0
- data/lib/gs_graph/connections/permissions.rb +16 -0
- data/lib/gs_graph/connections/photos.rb +21 -0
- data/lib/gs_graph/connections/picture.rb +39 -0
- data/lib/gs_graph/connections/pokes.rb +12 -0
- data/lib/gs_graph/connections/posts.rb +14 -0
- data/lib/gs_graph/connections/promotable_posts.rb +14 -0
- data/lib/gs_graph/connections/question_options.rb +14 -0
- data/lib/gs_graph/connections/questions.rb +22 -0
- data/lib/gs_graph/connections/reach_estimates.rb +12 -0
- data/lib/gs_graph/connections/roles.rb +36 -0
- data/lib/gs_graph/connections/scores.rb +22 -0
- data/lib/gs_graph/connections/senders.rb +14 -0
- data/lib/gs_graph/connections/settings.rb +65 -0
- data/lib/gs_graph/connections/statuses.rb +14 -0
- data/lib/gs_graph/connections/subscribed_to.rb +14 -0
- data/lib/gs_graph/connections/subscribers.rb +14 -0
- data/lib/gs_graph/connections/subscriptions.rb +53 -0
- data/lib/gs_graph/connections/tabs.rb +23 -0
- data/lib/gs_graph/connections/tagged.rb +14 -0
- data/lib/gs_graph/connections/tags.rb +23 -0
- data/lib/gs_graph/connections/television.rb +14 -0
- data/lib/gs_graph/connections/test_users.rb +19 -0
- data/lib/gs_graph/connections/threads.rb +14 -0
- data/lib/gs_graph/connections/user_achievements.rb +22 -0
- data/lib/gs_graph/connections/user_likes.rb +19 -0
- data/lib/gs_graph/connections/videos.rb +21 -0
- data/lib/gs_graph/connections/votes.rb +9 -0
- data/lib/gs_graph/cover.rb +10 -0
- data/lib/gs_graph/debugger.rb +28 -0
- data/lib/gs_graph/device.rb +11 -0
- data/lib/gs_graph/doc.rb +18 -0
- data/lib/gs_graph/domain.rb +32 -0
- data/lib/gs_graph/education.rb +32 -0
- data/lib/gs_graph/event.rb +52 -0
- data/lib/gs_graph/exception.rb +139 -0
- data/lib/gs_graph/friend_list.rb +13 -0
- data/lib/gs_graph/friend_request.rb +14 -0
- data/lib/gs_graph/group.rb +29 -0
- data/lib/gs_graph/image.rb +11 -0
- data/lib/gs_graph/insight.rb +13 -0
- data/lib/gs_graph/klass.rb +31 -0
- data/lib/gs_graph/link.rb +32 -0
- data/lib/gs_graph/location.rb +20 -0
- data/lib/gs_graph/message.rb +30 -0
- data/lib/gs_graph/milestone.rb +26 -0
- data/lib/gs_graph/node.rb +149 -0
- data/lib/gs_graph/note.rb +32 -0
- data/lib/gs_graph/notification.rb +32 -0
- data/lib/gs_graph/offer.rb +33 -0
- data/lib/gs_graph/open_graph.rb +3 -0
- data/lib/gs_graph/open_graph/action.rb +42 -0
- data/lib/gs_graph/open_graph/application_context.rb +10 -0
- data/lib/gs_graph/open_graph/object.rb +29 -0
- data/lib/gs_graph/open_graph/user_context.rb +21 -0
- data/lib/gs_graph/order.rb +55 -0
- data/lib/gs_graph/page.rb +57 -0
- data/lib/gs_graph/page/category_attributes.rb +117 -0
- data/lib/gs_graph/photo.rb +48 -0
- data/lib/gs_graph/picture.rb +14 -0
- data/lib/gs_graph/place.rb +7 -0
- data/lib/gs_graph/poke.rb +19 -0
- data/lib/gs_graph/post.rb +117 -0
- data/lib/gs_graph/privacy.rb +27 -0
- data/lib/gs_graph/project.rb +4 -0
- data/lib/gs_graph/promotable_post.rb +34 -0
- data/lib/gs_graph/property.rb +13 -0
- data/lib/gs_graph/query.rb +47 -0
- data/lib/gs_graph/question.rb +26 -0
- data/lib/gs_graph/question_option.rb +22 -0
- data/lib/gs_graph/reach_estimate.rb +22 -0
- data/lib/gs_graph/role.rb +13 -0
- data/lib/gs_graph/score.rb +16 -0
- data/lib/gs_graph/searchable.rb +33 -0
- data/lib/gs_graph/searchable/result.rb +31 -0
- data/lib/gs_graph/serialization.rb +19 -0
- data/lib/gs_graph/status.rb +27 -0
- data/lib/gs_graph/subscription.rb +14 -0
- data/lib/gs_graph/tab.rb +17 -0
- data/lib/gs_graph/tag.rb +30 -0
- data/lib/gs_graph/tagged_object.rb +23 -0
- data/lib/gs_graph/targeting.rb +23 -0
- data/lib/gs_graph/test_user.rb +24 -0
- data/lib/gs_graph/thread.rb +71 -0
- data/lib/gs_graph/user.rb +153 -0
- data/lib/gs_graph/user_achievement.rb +35 -0
- data/lib/gs_graph/venue.rb +14 -0
- data/lib/gs_graph/video.rb +41 -0
- data/lib/gs_graph/work.rb +48 -0
- data/lib/patch/rack/oauth2/access_token.rb +11 -0
- data/lib/patch/rack/oauth2/access_token/introspectable.rb +37 -0
- data/lib/patch/rack/oauth2/client.rb +13 -0
- data/lib/patch/rack/oauth2/grant/fb_exchange_token.rb +11 -0
- data/lib/patch/rack/oauth2/util.rb +14 -0
- data/spec/gs_graph/achievement_spec.rb +59 -0
- data/spec/gs_graph/ad_account_spec.rb +124 -0
- data/spec/gs_graph/ad_campaign_spec.rb +99 -0
- data/spec/gs_graph/ad_connection_object_spec.rb +71 -0
- data/spec/gs_graph/ad_creative_spec.rb +87 -0
- data/spec/gs_graph/ad_group_spec.rb +95 -0
- data/spec/gs_graph/ad_keyword_spec.rb +27 -0
- data/spec/gs_graph/ad_keyword_suggestion_spec.rb +17 -0
- data/spec/gs_graph/ad_keyword_valid_spec.rb +19 -0
- data/spec/gs_graph/ad_user_spec.rb +67 -0
- data/spec/gs_graph/album_spec.rb +93 -0
- data/spec/gs_graph/app_request_spec.rb +40 -0
- data/spec/gs_graph/application_spec.rb +251 -0
- data/spec/gs_graph/auth/cookie_spec.rb +29 -0
- data/spec/gs_graph/auth/signed_request_spec.rb +22 -0
- data/spec/gs_graph/auth_spec.rb +223 -0
- data/spec/gs_graph/broad_targeting_category_spec.rb +17 -0
- data/spec/gs_graph/checkin_spec.rb +42 -0
- data/spec/gs_graph/collection_spec.rb +50 -0
- data/spec/gs_graph/comment_spec.rb +31 -0
- data/spec/gs_graph/connection_spec.rb +42 -0
- data/spec/gs_graph/connections/accounts_spec.rb +78 -0
- data/spec/gs_graph/connections/achievements_spec.rb +27 -0
- data/spec/gs_graph/connections/activities_spec.rb +34 -0
- data/spec/gs_graph/connections/ad_accounts_spec.rb +28 -0
- data/spec/gs_graph/connections/ad_campaign_stat_spec.rb +35 -0
- data/spec/gs_graph/connections/ad_campaigns_spec.rb +36 -0
- data/spec/gs_graph/connections/ad_connection_objects_spec.rb +20 -0
- data/spec/gs_graph/connections/ad_creatives_spec.rb +29 -0
- data/spec/gs_graph/connections/ad_group_stat_spec.rb +54 -0
- data/spec/gs_graph/connections/ad_groups_spec.rb +92 -0
- data/spec/gs_graph/connections/ad_previews_spec.rb +18 -0
- data/spec/gs_graph/connections/admins_spec.rb +20 -0
- data/spec/gs_graph/connections/albums_spec.rb +63 -0
- data/spec/gs_graph/connections/app_notifications_spec.rb +23 -0
- data/spec/gs_graph/connections/app_requests_spec.rb +28 -0
- data/spec/gs_graph/connections/attending_spec.rb +47 -0
- data/spec/gs_graph/connections/banned_spec.rb +63 -0
- data/spec/gs_graph/connections/blocked_spec.rb +56 -0
- data/spec/gs_graph/connections/books_spec.rb +32 -0
- data/spec/gs_graph/connections/broad_targeting_categories_spec.rb +18 -0
- data/spec/gs_graph/connections/checkins_spec.rb +153 -0
- data/spec/gs_graph/connections/comments_spec.rb +75 -0
- data/spec/gs_graph/connections/conversations_spec.rb +19 -0
- data/spec/gs_graph/connections/declined_spec.rb +47 -0
- data/spec/gs_graph/connections/docs_spec.rb +14 -0
- data/spec/gs_graph/connections/events_spec.rb +52 -0
- data/spec/gs_graph/connections/family_spec.rb +32 -0
- data/spec/gs_graph/connections/feed_spec.rb +124 -0
- data/spec/gs_graph/connections/former_participants_spec.rb +44 -0
- data/spec/gs_graph/connections/friend_lists_spec.rb +26 -0
- data/spec/gs_graph/connections/friend_requests_spec.rb +16 -0
- data/spec/gs_graph/connections/friends_spec.rb +51 -0
- data/spec/gs_graph/connections/games_spec.rb +20 -0
- data/spec/gs_graph/connections/groups_spec.rb +31 -0
- data/spec/gs_graph/connections/home_spec.rb +62 -0
- data/spec/gs_graph/connections/inbox_spec.rb +16 -0
- data/spec/gs_graph/connections/insights_spec.rb +104 -0
- data/spec/gs_graph/connections/interests_spec.rb +12 -0
- data/spec/gs_graph/connections/invited_spec.rb +84 -0
- data/spec/gs_graph/connections/likes_spec.rb +127 -0
- data/spec/gs_graph/connections/links_spec.rb +31 -0
- data/spec/gs_graph/connections/maybe_spec.rb +47 -0
- data/spec/gs_graph/connections/members_spec.rb +57 -0
- data/spec/gs_graph/connections/messages_spec.rb +58 -0
- data/spec/gs_graph/connections/milestones_spec.rb +40 -0
- data/spec/gs_graph/connections/movies_spec.rb +12 -0
- data/spec/gs_graph/connections/music_spec.rb +12 -0
- data/spec/gs_graph/connections/mutual_friends_spec.rb +28 -0
- data/spec/gs_graph/connections/noreply_spec.rb +39 -0
- data/spec/gs_graph/connections/notes_spec.rb +31 -0
- data/spec/gs_graph/connections/notifications_spec.rb +30 -0
- data/spec/gs_graph/connections/outbox_spec.rb +16 -0
- data/spec/gs_graph/connections/participants_spec.rb +42 -0
- data/spec/gs_graph/connections/payments_spec.rb +17 -0
- data/spec/gs_graph/connections/permissions_spec.rb +44 -0
- data/spec/gs_graph/connections/photos_spec.rb +39 -0
- data/spec/gs_graph/connections/picture_spec.rb +92 -0
- data/spec/gs_graph/connections/pokes_spec.rb +16 -0
- data/spec/gs_graph/connections/posts_spec.rb +34 -0
- data/spec/gs_graph/connections/promotable_posts_spec.rb +24 -0
- data/spec/gs_graph/connections/question_options_spec.rb +14 -0
- data/spec/gs_graph/connections/questions_spec.rb +31 -0
- data/spec/gs_graph/connections/reach_estimates_spec.rb +18 -0
- data/spec/gs_graph/connections/roles_spec.rb +59 -0
- data/spec/gs_graph/connections/scores_spec.rb +40 -0
- data/spec/gs_graph/connections/senders_spec.rb +42 -0
- data/spec/gs_graph/connections/settings_spec.rb +62 -0
- data/spec/gs_graph/connections/statuses_spec.rb +72 -0
- data/spec/gs_graph/connections/subscribed_to_spec.rb +12 -0
- data/spec/gs_graph/connections/subscribers_spec.rb +12 -0
- data/spec/gs_graph/connections/subscriptions_spec.rb +47 -0
- data/spec/gs_graph/connections/tabs_spec.rb +47 -0
- data/spec/gs_graph/connections/tagged_spec.rb +42 -0
- data/spec/gs_graph/connections/tags_spec.rb +30 -0
- data/spec/gs_graph/connections/television_spec.rb +12 -0
- data/spec/gs_graph/connections/test_users_spec.rb +65 -0
- data/spec/gs_graph/connections/threads_spec.rb +12 -0
- data/spec/gs_graph/connections/user_achievements_spec.rb +37 -0
- data/spec/gs_graph/connections/user_likes_spec.rb +55 -0
- data/spec/gs_graph/connections/videos_spec.rb +27 -0
- data/spec/gs_graph/connections/votes_spec.rb +15 -0
- data/spec/gs_graph/debugger_spec.rb +33 -0
- data/spec/gs_graph/doc_spec.rb +27 -0
- data/spec/gs_graph/domain_spec.rb +23 -0
- data/spec/gs_graph/education_spec.rb +61 -0
- data/spec/gs_graph/event_spec.rb +70 -0
- data/spec/gs_graph/exception_spec.rb +310 -0
- data/spec/gs_graph/friend_list_spec.rb +22 -0
- data/spec/gs_graph/group_spec.rb +28 -0
- data/spec/gs_graph/image_spec.rb +16 -0
- data/spec/gs_graph/insight_spec.rb +18 -0
- data/spec/gs_graph/link_spec.rb +41 -0
- data/spec/gs_graph/location_spec.rb +28 -0
- data/spec/gs_graph/message_spec.rb +47 -0
- data/spec/gs_graph/node_spec.rb +91 -0
- data/spec/gs_graph/note_spec.rb +37 -0
- data/spec/gs_graph/notification_spec.rb +59 -0
- data/spec/gs_graph/offer_spec.rb +30 -0
- data/spec/gs_graph/open_graph/action_spec.rb +112 -0
- data/spec/gs_graph/open_graph/application_context_spec.rb +28 -0
- data/spec/gs_graph/open_graph/object_spec.rb +76 -0
- data/spec/gs_graph/open_graph/user_context_spec.rb +33 -0
- data/spec/gs_graph/order_spec.rb +66 -0
- data/spec/gs_graph/page/local_business_spec.rb +88 -0
- data/spec/gs_graph/page/movie_spec.rb +25 -0
- data/spec/gs_graph/page/music_spec.rb +25 -0
- data/spec/gs_graph/page/person_spec.rb +23 -0
- data/spec/gs_graph/page/product_spec.rb +36 -0
- data/spec/gs_graph/page_spec.rb +81 -0
- data/spec/gs_graph/photo_spec.rb +85 -0
- data/spec/gs_graph/place_spec.rb +8 -0
- data/spec/gs_graph/post_spec.rb +238 -0
- data/spec/gs_graph/privacy_spec.rb +33 -0
- data/spec/gs_graph/project_spec.rb +46 -0
- data/spec/gs_graph/promotable_post_spec.rb +57 -0
- data/spec/gs_graph/qeustion_option_spec.rb +35 -0
- data/spec/gs_graph/query_spec.rb +73 -0
- data/spec/gs_graph/question_spec.rb +73 -0
- data/spec/gs_graph/reach_estimate_spec.rb +48 -0
- data/spec/gs_graph/searchable_spec.rb +47 -0
- data/spec/gs_graph/seriarization_spec.rb +29 -0
- data/spec/gs_graph/status_spec.rb +31 -0
- data/spec/gs_graph/subscription_spec.rb +5 -0
- data/spec/gs_graph/tag_spec.rb +34 -0
- data/spec/gs_graph/tagged_object_spec.rb +45 -0
- data/spec/gs_graph/targeting_spec.rb +34 -0
- data/spec/gs_graph/test_user_spec.rb +50 -0
- data/spec/gs_graph/thread_spec.rb +86 -0
- data/spec/gs_graph/user_achievement_spec.rb +53 -0
- data/spec/gs_graph/user_spec.rb +185 -0
- data/spec/gs_graph/venue_spec.rb +23 -0
- data/spec/gs_graph/video_spec.rb +31 -0
- data/spec/gs_graph/work_spec.rb +101 -0
- data/spec/gs_graph_spec.rb +57 -0
- data/spec/spec_helper.rb +9 -0
- metadata +538 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class AdGroup < Node
|
3
|
+
include Connections::AdCreatives
|
4
|
+
include Connections::ReachEstimates
|
5
|
+
|
6
|
+
attr_accessor :ad_id, :campaign_id, :name, :adgroup_status, :bid_type, :max_bid, :targeting, :creative, :creative_ids, :adgroup_id,
|
7
|
+
:end_time, :start_time, :updated_time, :bid_info, :disapprove_reason_descriptions, :view_tags
|
8
|
+
|
9
|
+
def initialize(identifier, attributes = {})
|
10
|
+
super
|
11
|
+
set_attrs(attributes)
|
12
|
+
end
|
13
|
+
|
14
|
+
# We override update to handle the "redownload" parameter
|
15
|
+
# If redownload is specified, the GSGraph::AdGroup object will be updated with the data returned from Facebook.
|
16
|
+
def update(options)
|
17
|
+
response = super(options)
|
18
|
+
|
19
|
+
if options[:redownload]
|
20
|
+
attributes = options.merge(response[:data][:adgroups][identifier]).with_indifferent_access
|
21
|
+
set_attrs(attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
def creatives(fetch = true)
|
28
|
+
creative_ids.map { |creative_id| fetch ? AdCreative.fetch(creative_id) : AdCreative.new(creative_id) }
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def set_attrs(attributes)
|
34
|
+
%w(ad_id campaign_id name adgroup_status bid_type max_bid targeting creative creative_ids adgroup_id bid_info disapprove_reason_descriptions view_tags).each do |field|
|
35
|
+
send("#{field}=", attributes[field.to_sym])
|
36
|
+
end
|
37
|
+
|
38
|
+
# max_bid is string only when reloaded for some reason..
|
39
|
+
self.max_bid = max_bid.try(:to_i)
|
40
|
+
|
41
|
+
%w(start_time end_time updated_time).each do |field|
|
42
|
+
if val = attributes[field.to_sym]
|
43
|
+
# Handles integer timestamps and ISO8601 strings
|
44
|
+
time = Time.parse(val) rescue Time.at(val.to_i)
|
45
|
+
send("#{field}=", time)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class AdGroupStat < Node
|
3
|
+
attr_accessor :start_time, :end_time, :adgroup_id, :impressions, :clicks, :spent, :social_impressions, :social_clicks, :social_spent,
|
4
|
+
:actions, :unique_impressions, :social_unique_impressions, :unique_clicks, :social_unique_clicks, :connections
|
5
|
+
|
6
|
+
def initialize(identifier, attributes = {})
|
7
|
+
super
|
8
|
+
|
9
|
+
%w(adgroup_id impressions clicks spent social_impressions social_clicks social_spent actions unique_impressions social_unique_impressions unique_clicks social_unique_clicks connections).each do |field|
|
10
|
+
send("#{field}=", attributes[field.to_sym])
|
11
|
+
end
|
12
|
+
|
13
|
+
%w(start_time end_time).each do |field|
|
14
|
+
if val = attributes[field.to_sym]
|
15
|
+
# Handles integer timestamps and ISO8601 strings
|
16
|
+
time = Time.parse(val) rescue Time.at(val.to_i)
|
17
|
+
send("#{field}=", time)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class AdKeyword < Node
|
3
|
+
extend Searchable
|
4
|
+
|
5
|
+
attr_accessor :name, :description
|
6
|
+
|
7
|
+
def initialize(identifier, attributes = {})
|
8
|
+
super
|
9
|
+
|
10
|
+
%w(name description).each do |field|
|
11
|
+
self.send("#{field}=", attributes[field.to_sym])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def topic_keyword?
|
16
|
+
(name =~ /^#/) == 0
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class AdKeywordValid < Node
|
3
|
+
extend Searchable
|
4
|
+
|
5
|
+
attr_accessor :name, :valid, :suggestions
|
6
|
+
|
7
|
+
def initialize(identifier, attributes = {})
|
8
|
+
super
|
9
|
+
|
10
|
+
%w(name valid).each do |field|
|
11
|
+
self.send("#{field}=", attributes[field.to_sym])
|
12
|
+
end
|
13
|
+
|
14
|
+
self.suggestions = attributes[:suggestions].collect {|s| GSGraph::AdKeyword.new(s['id'], s)} if attributes[:suggestions]
|
15
|
+
end
|
16
|
+
|
17
|
+
alias :valid? :valid
|
18
|
+
|
19
|
+
def self.search_query_param
|
20
|
+
:keyword_list
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class AdUser < User
|
3
|
+
attr_accessor :role, :permissions
|
4
|
+
|
5
|
+
def initialize(identifier, attributes = {})
|
6
|
+
super(identifier, attributes)
|
7
|
+
|
8
|
+
%w(role permissions).each do |field|
|
9
|
+
self.send("#{field}=", attributes[field.to_sym])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Level 1001, administrator access
|
14
|
+
# Level 1002, general-user (ad manager) access
|
15
|
+
# Level 1003, reports-only access
|
16
|
+
ROLES = {
|
17
|
+
:admin => 1001,
|
18
|
+
:general => 1002,
|
19
|
+
:reports_only => 1003
|
20
|
+
}
|
21
|
+
ROLES.each do |key, value|
|
22
|
+
define_method "#{key}_access?" do
|
23
|
+
self.role == value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# 1: ACCOUNT_ADMIN: modify the set of users associated with the given account.
|
28
|
+
# 2: ADMANAGER_READ: view campaigns and ads
|
29
|
+
# 3: ADMANAGER_WRITE: manage campaigns and ads
|
30
|
+
# 4: BILLING_READ: view account billing information
|
31
|
+
# 5: BILLING_WRITE: modify the account billing information
|
32
|
+
# 7: REPORTS: run reports
|
33
|
+
PERMISSIONS = {
|
34
|
+
:account_admin => 1,
|
35
|
+
:ad_manager_read => 2,
|
36
|
+
:ad_manager_write => 3,
|
37
|
+
:billing_read => 4,
|
38
|
+
:billing_write => 5,
|
39
|
+
# what's "6"??
|
40
|
+
:reports => 7
|
41
|
+
}
|
42
|
+
PERMISSIONS.each do |key, value|
|
43
|
+
define_method "#{key}_access?" do
|
44
|
+
self.permissions.include? value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# GSGraph::User#fetch does not retrieve the permissions and roles since they are outside the normal
|
49
|
+
# attributes for an GSGraph::User, so we just copy them over from this object before returning
|
50
|
+
# the fetched one.
|
51
|
+
def fetch(options = {})
|
52
|
+
super(options).tap do |fetched|
|
53
|
+
fetched.role = role
|
54
|
+
fetched.permissions = permissions
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class Album < Node
|
3
|
+
include Connections::Photos
|
4
|
+
include Connections::Comments
|
5
|
+
include Connections::Likes
|
6
|
+
include Connections::Likes::Likable
|
7
|
+
include Connections::Picture
|
8
|
+
|
9
|
+
attr_accessor :from, :name, :description, :location, :link, :cover_photo, :privacy, :count, :type, :created_time, :updated_time
|
10
|
+
|
11
|
+
def initialize(identifier, attributes = {})
|
12
|
+
super
|
13
|
+
@from = if (from = attributes[:from])
|
14
|
+
if from[:category]
|
15
|
+
Page.new(from[:id], from)
|
16
|
+
else
|
17
|
+
User.new(from[:id], from)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@name = attributes[:name]
|
21
|
+
# NOTE:
|
22
|
+
# for some reason, facebook uses different parameter names.
|
23
|
+
# "description" in GET & "message" in POST
|
24
|
+
@description = attributes[:description] || attributes[:message]
|
25
|
+
@location = attributes[:location]
|
26
|
+
@link = attributes[:link]
|
27
|
+
@privacy = attributes[:privacy]
|
28
|
+
@count = attributes[:count]
|
29
|
+
@type = attributes[:type]
|
30
|
+
|
31
|
+
@cover_photo = if attributes[:cover_photo]
|
32
|
+
Photo.new(attributes[:cover_photo])
|
33
|
+
end
|
34
|
+
@created_time = if attributes[:created_time]
|
35
|
+
Time.parse(attributes[:created_time]).utc
|
36
|
+
end
|
37
|
+
@updated_time = if attributes[:updated_time]
|
38
|
+
Time.parse(attributes[:updated_time]).utc
|
39
|
+
end
|
40
|
+
|
41
|
+
# cached connection
|
42
|
+
cache_collection attributes, :comments
|
43
|
+
end
|
44
|
+
|
45
|
+
def picture_with_access_token(options_or_size = {})
|
46
|
+
response = picture_without_access_token options_or_size
|
47
|
+
if response.is_a?(GSGraph::Picture)
|
48
|
+
response
|
49
|
+
else
|
50
|
+
_endpoint_ = URI.parse response
|
51
|
+
if self.access_token
|
52
|
+
_endpoint_.query = [_endpoint_.query, {:access_token => self.access_token.to_s}.to_query].compact.join('&')
|
53
|
+
end
|
54
|
+
_endpoint_.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias_method_chain :picture, :access_token
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class AppRequest < Node
|
3
|
+
|
4
|
+
attr_accessor :application, :created_time, :data, :from, :message, :to
|
5
|
+
|
6
|
+
def initialize(identifier, attributes = {})
|
7
|
+
super
|
8
|
+
@data = attributes[:data]
|
9
|
+
@message = attributes[:message]
|
10
|
+
if attributes[:from]
|
11
|
+
@from = User.new(attributes[:from][:id], attributes[:from])
|
12
|
+
end
|
13
|
+
if attributes[:to]
|
14
|
+
@to = User.new(attributes[:to][:id], attributes[:to])
|
15
|
+
end
|
16
|
+
if attributes[:application]
|
17
|
+
@application = Application.new(attributes[:application][:id], attributes[:application])
|
18
|
+
end
|
19
|
+
if attributes[:created_time]
|
20
|
+
@created_time = Time.parse(attributes[:created_time]).utc
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class Application < Node
|
3
|
+
include Connections::Accounts
|
4
|
+
include Connections::Achievements
|
5
|
+
include Connections::AppNotifications
|
6
|
+
include Connections::Banned
|
7
|
+
include Connections::Insights
|
8
|
+
include Connections::Payments
|
9
|
+
include Connections::Picture
|
10
|
+
include Connections::Roles
|
11
|
+
include Connections::Subscriptions
|
12
|
+
include Connections::TestUsers
|
13
|
+
include Connections::Videos
|
14
|
+
include OpenGraph::ApplicationContext
|
15
|
+
|
16
|
+
@@attributes = [
|
17
|
+
:name,
|
18
|
+
:namespace,
|
19
|
+
:description,
|
20
|
+
:canvas_name,
|
21
|
+
:category,
|
22
|
+
:subcategory,
|
23
|
+
:link,
|
24
|
+
:company,
|
25
|
+
:icon_url,
|
26
|
+
:logo_url,
|
27
|
+
:daily_active_users,
|
28
|
+
:weekly_active_users,
|
29
|
+
:monthly_active_users,
|
30
|
+
:migrations,
|
31
|
+
:namespace,
|
32
|
+
:restrictions,
|
33
|
+
:app_domains,
|
34
|
+
:auth_dialog_data_help_url,
|
35
|
+
:auth_dialog_description,
|
36
|
+
:auth_dialog_headline,
|
37
|
+
:auth_dialog_perms_explanation,
|
38
|
+
:auth_referral_user_perms,
|
39
|
+
:auth_referral_friend_perms,
|
40
|
+
:auth_referral_default_activity_privacy,
|
41
|
+
:auth_referral_enabled,
|
42
|
+
:auth_referral_extended_perms,
|
43
|
+
:auth_referral_response_type,
|
44
|
+
:canvas_fluid_height,
|
45
|
+
:canvas_fluid_width,
|
46
|
+
:canvas_url,
|
47
|
+
:contact_email,
|
48
|
+
:created_time,
|
49
|
+
:creator_uid,
|
50
|
+
:deauth_callback_url,
|
51
|
+
:iphone_app_store_id,
|
52
|
+
:hosting_url,
|
53
|
+
:mobile_web_url,
|
54
|
+
:page_tab_default_name,
|
55
|
+
:page_tab_url,
|
56
|
+
:privacy_policy_url,
|
57
|
+
:secure_canvas_url,
|
58
|
+
:secure_page_tab_url,
|
59
|
+
:server_ip_whitelist,
|
60
|
+
:social_discovery,
|
61
|
+
:terms_of_service_url,
|
62
|
+
:user_support_email,
|
63
|
+
:user_support_url,
|
64
|
+
:website_url,
|
65
|
+
:type,
|
66
|
+
:secret
|
67
|
+
]
|
68
|
+
attr_accessor *@@attributes
|
69
|
+
|
70
|
+
def initialize(client_id, attributes = {})
|
71
|
+
super
|
72
|
+
@@attributes.each do |key|
|
73
|
+
# NOTE:
|
74
|
+
# For some reason, Graph API returns daily_active_users, weekly_active_users, monthly_active_users as JSON string.
|
75
|
+
value = case key
|
76
|
+
when :daily_active_users, :weekly_active_users, :monthly_active_users
|
77
|
+
attributes[key].to_i
|
78
|
+
when :auth_referral_enabled, :canvas_fluid_height, :canvas_fluid_width, :social_discovery
|
79
|
+
case attributes[key]
|
80
|
+
when 1
|
81
|
+
true
|
82
|
+
when 0
|
83
|
+
false
|
84
|
+
else
|
85
|
+
attributes[key]
|
86
|
+
end
|
87
|
+
else
|
88
|
+
attributes[key]
|
89
|
+
end
|
90
|
+
self.send("#{key}=", value)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_access_token(secret = nil)
|
95
|
+
self.secret ||= secret
|
96
|
+
auth = Auth.new(self.identifier, self.secret)
|
97
|
+
self.access_token = auth.client.access_token! :client_auth_body
|
98
|
+
end
|
99
|
+
alias_method :app_access_token, :get_access_token
|
100
|
+
|
101
|
+
def access_token_with_auto_fetch
|
102
|
+
access_token_without_auto_fetch ||
|
103
|
+
self.secret && get_access_token
|
104
|
+
end
|
105
|
+
alias_method_chain :access_token, :auto_fetch
|
106
|
+
|
107
|
+
def debug_token(input_token)
|
108
|
+
_input_token_ = case input_token
|
109
|
+
when Rack::OAuth2::AccessToken::Legacy
|
110
|
+
input_token
|
111
|
+
else
|
112
|
+
Rack::OAuth2::AccessToken::Legacy.new(
|
113
|
+
:access_token => input_token
|
114
|
+
)
|
115
|
+
end
|
116
|
+
_input_token_.introspect access_token
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module GSGraph
|
2
|
+
class Auth
|
3
|
+
class VerificationFailed < BadRequest; end
|
4
|
+
|
5
|
+
attr_accessor :client, :access_token, :user, :data
|
6
|
+
|
7
|
+
def initialize(client_id, client_secret, options = {})
|
8
|
+
@client = Rack::OAuth2::Client.new(
|
9
|
+
:identifier => client_id,
|
10
|
+
:secret => client_secret,
|
11
|
+
:host => URI.parse(GSGraph::graph_url).host,
|
12
|
+
:authorization_endpoint => '/oauth/authorize',
|
13
|
+
:token_endpoint => '/oauth/access_token',
|
14
|
+
:redirect_uri => options[:redirect_uri]
|
15
|
+
)
|
16
|
+
if options[:cookie]
|
17
|
+
from_cookie options[:cookie]
|
18
|
+
elsif options[:signed_request]
|
19
|
+
from_signed_request options[:signed_request]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def authorized?
|
24
|
+
self.access_token.present?
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorize_uri(canvas_uri, options = {})
|
28
|
+
endpoint = URI.parse SignedRequest::oauth_dialog_endpoint
|
29
|
+
params = options.merge(
|
30
|
+
:client_id => client.identifier,
|
31
|
+
:redirect_uri => canvas_uri
|
32
|
+
)
|
33
|
+
params[:scope] = Array(params[:scope]).join(',') if params[:scope].present?
|
34
|
+
endpoint.query = params.to_query
|
35
|
+
endpoint.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def from_cookie(cookie)
|
39
|
+
self.data = Cookie.parse(client, cookie)
|
40
|
+
get_access_token! data[:code]
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def from_signed_request(signed_request)
|
45
|
+
self.data = SignedRequest.verify(client, signed_request)
|
46
|
+
if self.data[:oauth_token]
|
47
|
+
self.access_token = build_access_token(data)
|
48
|
+
self.user = User.new(data[:user_id], :access_token => self.access_token)
|
49
|
+
end
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def exchange_token!(access_token)
|
54
|
+
raise Unauthorized.new('No Access Token') unless access_token
|
55
|
+
client.fb_exchange_token = access_token
|
56
|
+
self.access_token = client.access_token! :client_auth_body
|
57
|
+
self
|
58
|
+
rescue Rack::OAuth2::Client::Error => e
|
59
|
+
Exception.handle_rack_oauth2_error e
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def get_access_token!(code)
|
65
|
+
raise Unauthorized.new('No Authorization Code') unless code
|
66
|
+
client.redirect_uri = ''
|
67
|
+
client.authorization_code = code
|
68
|
+
self.access_token = client.access_token! :client_auth_body
|
69
|
+
self.user = User.new(data[:user_id], :access_token => access_token)
|
70
|
+
self
|
71
|
+
rescue Rack::OAuth2::Client::Error => e
|
72
|
+
Exception.handle_rack_oauth2_error e
|
73
|
+
end
|
74
|
+
|
75
|
+
def build_access_token(data)
|
76
|
+
expires_in = unless data[:expires].nil? || data[:expires].zero?
|
77
|
+
data[:expires] - Time.now.to_i
|
78
|
+
end
|
79
|
+
Rack::OAuth2::AccessToken::Legacy.new(
|
80
|
+
:access_token => data[:oauth_token] || data[:access_token],
|
81
|
+
:expires_in => expires_in
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
require 'gs_graph/auth/cookie'
|
88
|
+
require 'gs_graph/auth/signed_request'
|