Class: AWeber::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aweber/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/aweber/base.rb', line 4

def initialize(oauth)
  @oauth = oauth
end

Class Method Details

.authorize_with_authorization_code(auth_code) ⇒ Object

Authorize an app with an auth code from 1.0/oauth/authorize_app/app_id

/authorize_app to be used for authorization.

Parameters:

  • auth_code (string)

    The authorization code received from



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/aweber/base.rb', line 43

def self.authorize_with_authorization_code(auth_code)
  consumer_token, consumer_secret, request_token, request_secret, verifier =
      auth_code.split('|')
  oauth = AWeber::OAuth.new(consumer_token, consumer_secret)

  request_hash = {:oauth_token => request_token, :oauth_token_secret => request_secret}
  request = ::OAuth::RequestToken.from_hash(oauth.consumer, request_hash)

  oauth.request_token = request
  oauth.authorize_with_verifier(verifier)
  self.new(oauth)
end

Instance Method Details

#accountObject



8
9
10
# File 'lib/aweber/base.rb', line 8

def 
  accounts.first.last
end

#delete(uri) ⇒ Object



18
19
20
# File 'lib/aweber/base.rb', line 18

def delete(uri)
  oauth.delete(expand(uri))
end

#get(uri) ⇒ Object



12
13
14
15
16
# File 'lib/aweber/base.rb', line 12

def get(uri)
  response = oauth.get(expand(uri))
  handle_errors(response, uri)
  parse(response) if response
end

#inspectObject



34
35
36
# File 'lib/aweber/base.rb', line 34

def inspect
  "#<AWeber::Base />"
end

#pathObject



30
31
32
# File 'lib/aweber/base.rb', line 30

def path
  ""
end

#post(uri, body = {}) ⇒ Object



22
23
24
# File 'lib/aweber/base.rb', line 22

def post(uri, body={})
  oauth.post(expand(uri), body)
end

#put(uri, body = {}) ⇒ Object



26
27
28
# File 'lib/aweber/base.rb', line 26

def put(uri, body={})
  oauth.put(uri, body.to_json, {"Content-Type" => "application/json"})
end