Class: Wordstream::Client
- Inherits:
-
Object
- Object
- Wordstream::Client
- Includes:
- HTTParty
- Defined in:
- lib/wordstream.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #get_api_credits ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #logout ⇒ Object
- #response(resp) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
15 16 17 |
# File 'lib/wordstream.rb', line 15 def initialize(username, password) @username, @password = username, password end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
14 15 16 |
# File 'lib/wordstream.rb', line 14 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
14 15 16 |
# File 'lib/wordstream.rb', line 14 def username @username end |
Instance Method Details
#get_api_credits ⇒ Object
29 30 31 |
# File 'lib/wordstream.rb', line 29 def get_api_credits response(self.class.get('/authentication/get_api_credits')) end |
#login ⇒ Object
19 20 21 22 23 |
# File 'lib/wordstream.rb', line 19 def login resp = self.class.get('/authentication/login', :query => {:username => @username, :password => @password}) parsed = response(resp) self.class.default_params :session_id => parsed.data.session_id end |
#logout ⇒ Object
25 26 27 |
# File 'lib/wordstream.rb', line 25 def logout response( self.class.get('/authentication/logout') ) end |
#response(resp) ⇒ Object
33 34 35 |
# File 'lib/wordstream.rb', line 33 def response(resp) Hashie::Mash.new (JSON.parse( resp.match(/response\((.*)\)/)[1]) ) end |