Class: RubychinaApi::Client
- Inherits:
-
Object
- Object
- RubychinaApi::Client
- Defined in:
- lib/rubychina_api/client.rb
Instance Attribute Summary collapse
-
#avatar_url ⇒ Object
readonly
Returns the value of attribute avatar_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Client
constructor
A new instance of Client.
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"] = attributes["meta"] end |
Instance Attribute Details
#avatar_url ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/rubychina_api/client.rb', line 3 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
3 4 5 |
# File 'lib/rubychina_api/client.rb', line 3 def end |
#name ⇒ Object (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.login(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 |