Class: NationBuilder::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nation_builder/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client



5
6
7
8
9
10
11
# File 'lib/nation_builder/client.rb', line 5

def initialize(args = {})
  args.each do |key, value|
    self.send("#{key}=".intern, value)
  end
  client = OAuth2::Client.new(client_id, client_secret, :site => "https://#{hostname}", authorize_url: "https://#{hostname}/oauth/authorize", token_url: "https://#{hostname}/oauth/token" )
  self.token = client.password.get_token(username, password)
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



3
4
5
# File 'lib/nation_builder/client.rb', line 3

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



3
4
5
# File 'lib/nation_builder/client.rb', line 3

def client_secret
  @client_secret
end

#hostnameObject

Returns the value of attribute hostname.



3
4
5
# File 'lib/nation_builder/client.rb', line 3

def hostname
  @hostname
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/nation_builder/client.rb', line 3

def password
  @password
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/nation_builder/client.rb', line 3

def token
  @token
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/nation_builder/client.rb', line 3

def username
  @username
end

Instance Method Details

#get(path) ⇒ Object



18
19
20
# File 'lib/nation_builder/client.rb', line 18

def get(path)
  self.token.get "https://#{hostname}/#{path}"
end

#peopleObject



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

def people
  NationBuilder::People.new(self)
end