Class: RubychinaApi::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Client

Returns a new instance of Client.



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

def initialize(attributes)
  @id = attributes["id"]
  @name = attributes["name"]
  @avatar_url = attributes["avatar_url"]
  @meta = attributes["meta"]
end

Instance Attribute Details

#avatar_urlObject (readonly)

Returns the value of attribute avatar_url.



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

def avatar_url
  @avatar_url
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



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

def meta
  @meta
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.login(option) ⇒ Object



12
13
14
15
16
17
# File 'lib/rubychina_api/client.rb', line 12

def self.(option)
  client = OAuth2::Client.new(RubychinaApi::Config.client_id, RubychinaApi::Config.secret, site: 'https://ruby-china.org')
  RubychinaApi::Config.access_token = client.password.get_token(option["username"], option["password"]).token
  response = RubychinaApi::Operation.get("hello")
  new(JSON.parse(response.body).fetch("user"))
end