Class: Rutt::Instapaper::API

Inherits:
Object
  • Object
show all
Defined in:
lib/rutt/share/instapaper.rb

Constant Summary collapse

Url =
"http://www.instapaper.com"

Instance Method Summary collapse

Constructor Details

#initialize(consumer_key, consumer_secret) ⇒ API

Returns a new instance of API.



6
7
8
9
# File 'lib/rutt/share/instapaper.rb', line 6

def initialize(consumer_key, consumer_secret)
  @consumer_key    = consumer_key
  @consumer_secret = consumer_secret
end

Instance Method Details

#authorize(username, password) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rutt/share/instapaper.rb', line 11

def authorize(username, password)
  @consumer = OAuth::Consumer.new(@consumer_key, @consumer_secret, {
      :site              => "https://www.instapaper.com",
      :access_token_path => "/api/1/oauth/access_token",
      :http_method => :post
    })

  access_token = @consumer.get_access_token(nil, {}, {
      :x_auth_username => username,
      :x_auth_password => password,
      :x_auth_mode     => "client_auth",
    })

  @access_token = OAuth::AccessToken.new(@consumer, access_token.token, access_token.secret)
end

#request(path, params = {}) ⇒ Object



27
28
29
# File 'lib/rutt/share/instapaper.rb', line 27

def request(path, params={})
  @access_token.request(:post, "#{Url}#{path}", params)
end