Class: Wordstream::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/wordstream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#passwordObject

Returns the value of attribute password.



14
15
16
# File 'lib/wordstream.rb', line 14

def password
  @password
end

#usernameObject

Returns the value of attribute username.



14
15
16
# File 'lib/wordstream.rb', line 14

def username
  @username
end

Instance Method Details

#get_api_creditsObject



29
30
31
# File 'lib/wordstream.rb', line 29

def get_api_credits
  response(self.class.get('/authentication/get_api_credits'))
end

#loginObject



19
20
21
22
23
# File 'lib/wordstream.rb', line 19

def 
  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

#logoutObject



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