Class: EventMachine::Instagram
- Inherits:
-
Object
- Object
- EventMachine::Instagram
- Includes:
- Media, Subscriptions
- Defined in:
- lib/em-instagram.rb,
lib/em-instagram/server.rb,
lib/em-instagram/request.rb,
lib/em-instagram/version.rb,
lib/em-instagram/api/media.rb,
lib/em-instagram/api/subscriptions.rb
Defined Under Namespace
Modules: Media, Server, Subscriptions Classes: Request
Constant Summary collapse
- BASE_URI =
'https://api.instagram.com'
- PORT =
443
- VERSION =
'0.1.3'
Instance Attribute Summary collapse
-
#callback_url ⇒ Object
readonly
Returns the value of attribute callback_url.
-
#default_params ⇒ Object
readonly
Returns the value of attribute default_params.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#subscription_queue ⇒ Object
readonly
Returns the value of attribute subscription_queue.
-
#update_callback ⇒ Object
readonly
Returns the value of attribute update_callback.
Instance Method Summary collapse
- #fetch(update) ⇒ Object
-
#initialize(options = nil) ⇒ Instagram
constructor
A new instance of Instagram.
- #on_update(&block) ⇒ Object
- #receive_notification(data) ⇒ Object
- #request(method, path, options = {}) ⇒ Object
- #start_server(&block) ⇒ Object
- #stream(&block) ⇒ Object
- #update(data = nil) ⇒ Object
Methods included from Media
#fetch_geography, #fetch_tag, #media, #media_by_geography, #media_by_tag
Methods included from Subscriptions
#subscribe, #subscribe_next, #subscribe_to, #subscriptions, #unsubscribe
Constructor Details
#initialize(options = nil) ⇒ Instagram
Returns a new instance of Instagram.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/em-instagram.rb', line 17 def initialize( = nil) @host, @port, @server = [[:host], [:port], [:server]] @subscription_queue = EventMachine::Queue.new @update_queue = EventMachine::Queue.new @callback_url = [:callback_url] @default_stream = Proc.new{|update| self.fetch update} self.logger = [:logger] @default_params = {:client_id => [:client_id], :client_secret => [:client_secret]} update end |
Instance Attribute Details
#callback_url ⇒ Object (readonly)
Returns the value of attribute callback_url.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def callback_url @callback_url end |
#default_params ⇒ Object (readonly)
Returns the value of attribute default_params.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def default_params @default_params end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def server @server end |
#subscription_queue ⇒ Object (readonly)
Returns the value of attribute subscription_queue.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def subscription_queue @subscription_queue end |
#update_callback ⇒ Object (readonly)
Returns the value of attribute update_callback.
15 16 17 |
# File 'lib/em-instagram.rb', line 15 def update_callback @update_callback end |
Instance Method Details
#fetch(update) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/em-instagram.rb', line 29 def fetch(update) case update['object'] when 'geography' fetch_geography update['object_id'] when 'tag' fetch_tag update['object_id'] end end |
#on_update(&block) ⇒ Object
52 53 54 |
# File 'lib/em-instagram.rb', line 52 def on_update(&block) @update_callback = block end |
#receive_notification(data) ⇒ Object
68 69 70 71 |
# File 'lib/em-instagram.rb', line 68 def receive_notification(data) stream_set = @streams.nil? ? [@default_stream] : @streams stream_set.each { |stream| stream.call(data) } end |
#request(method, path, options = {}) ⇒ Object
73 74 75 76 |
# File 'lib/em-instagram.rb', line 73 def request(method, path, = {}) url = URI.join(BASE_URI, path).to_s Request.new EventMachine::HttpRequest.new(url).send(method, ) end |
#start_server(&block) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/em-instagram.rb', line 78 def start_server(&block) @host ||= '0.0.0.0' @port ||= 8080 @server ||= Server EventMachine.start_server(host, port, server) do |connection| connection.subscriber = self end end |
#stream(&block) ⇒ Object
47 48 49 50 |
# File 'lib/em-instagram.rb', line 47 def stream(&block) @streams ||= [] @streams << block end |
#update(data = nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/em-instagram.rb', line 56 def update(data = nil) @update_queue << data if data @update_queue.pop do |item| if @update_callback @update_callback.call(item) else self.logger.debug(item) end EventMachine::next_tick { update } end end |