Module: Instagram::Client::Subscriptions
- Included in:
- Instagram::Client
- Defined in:
- lib/instagram-fixed/client/subscriptions.rb
Overview
Defines methods related to real-time
Instance Method Summary collapse
-
#create_subscription(*args) ⇒ Object
Creates a real-time subscription.
-
#delete_subscription(*args) ⇒ Object
Deletes a real-time subscription.
-
#process_subscription(json, &block) ⇒ nil
Process a subscription notification JSON payload.
-
#subscriptions(options = {}) ⇒ Hashie::Mash
Returns a list of active real-time subscriptions.
Instance Method Details
#create_subscription(options = {}) ⇒ Object #create_subscription(object, callback_url, aspect = "media", options = {}) ⇒ Hashie::Mash
Creates a real-time subscription
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/instagram-fixed/client/subscriptions.rb', line 55 def create_subscription(*args) = args.last.is_a?(Hash) ? args.pop : {} object = args.shift callback_url = args.shift aspect = args.shift .tap {|o| o[:object] = object unless object.nil? o[:callback_url] = callback_url unless callback_url.nil? o[:aspect] = aspect || o[:aspect] || "media" } response = post("subscriptions", .merge(:client_secret => client_secret)) response["data"] end |
#delete_subscription(options = {}) ⇒ Object #delete_subscription(subscription_id, options = {}) ⇒ nil
Deletes a real-time subscription
90 91 92 93 94 95 96 |
# File 'lib/instagram-fixed/client/subscriptions.rb', line 90 def delete_subscription(*args) = args.last.is_a?(Hash) ? args.pop : {} subscription_id = args.first .merge!(:id => subscription_id) if subscription_id response = delete("subscriptions", .merge(:client_secret => client_secret)) response["data"] end |
#process_subscription(json, &block) ⇒ nil
Process a subscription notification JSON payload
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/instagram-fixed/client/subscriptions.rb', line 123 def process_subscription(json, ={}, &block) raise ArgumentError, "callbacks block expected" unless block_given? if [:signature] if !client_secret raise ArgumentError, "client_secret must be set during configure" end digest = OpenSSL::Digest::Digest.new('sha1') verify_signature = OpenSSL::HMAC.hexdigest(digest, client_secret, json) if [:signature] != verify_signature raise Instagram::InvalidSignature, "invalid X-Hub-Signature does not match verify signature against client_secret" end end payload = MultiJson.decode(json) @changes = Hash.new { |h,k| h[k] = [] } for change in payload @changes[change['object']] << change end block.call(self) end |
#subscriptions(options = {}) ⇒ Hashie::Mash
Returns a list of active real-time subscriptions
19 20 21 22 |
# File 'lib/instagram-fixed/client/subscriptions.rb', line 19 def subscriptions(={}) response = get("subscriptions", .merge(:client_secret => client_secret)) response["data"] end |