Class: Singly::Account
- Inherits:
-
Object
- Object
- Singly::Account
- Defined in:
- lib/singly/account.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
- #account_id ⇒ Object
-
#apply(service, params) ⇒ Object
Shortcut to Singly.auth.<service>.apply(account: <account_id>, token: <token> [, token_secret: <token_secret>]) where <account_id> is always this account’s account_id.
-
#delete(service, id = nil) ⇒ Object
Alternative to calling #profiles.<service>.delete.
- #friends ⇒ Object
- #id(id, params = {}) ⇒ Object
-
#initialize(access_token, account = nil) ⇒ Account
constructor
A new instance of Account.
-
#merge(source) ⇒ Object
Shortcut to Singly.auth.merge(source: <source>, dest: <dest>) where <dest> is always this account’s access_token.
- #profile ⇒ Object
- #profiles(params = {}) ⇒ Object
- #proxy ⇒ Object
- #services ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(access_token, account = nil) ⇒ Account
Returns a new instance of Account.
5 6 7 8 |
# File 'lib/singly/account.rb', line 5 def initialize(access_token, account=nil) @access_token = access_token @account = account end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/singly/account.rb', line 3 def access_token @access_token end |
Instance Method Details
#account_id ⇒ Object
10 11 12 |
# File 'lib/singly/account.rb', line 10 def account_id @account ||= profiles.fetch["id"] end |
#apply(service, params) ⇒ Object
Shortcut to Singly.auth.<service>.apply(account: <account_id>, token: <token> [, token_secret: <token_secret>]) where <account_id> is always this account’s account_id. If the account_id is not present, it is fetched from the api.
59 60 61 |
# File 'lib/singly/account.rb', line 59 def apply(service, params) Singly.auth.send(service).apply(params.merge(account: account_id)) end |
#delete(service, id = nil) ⇒ Object
Alternative to calling #profiles.<service>.delete. Useful if you don’t know the exact service at runtime.
44 45 46 47 48 |
# File 'lib/singly/account.rb', line 44 def delete(service, id=nil) endpoint = Singly::Profiles::Service.new(access_token: access_token) endpoint.service = service endpoint.delete(id) end |
#friends ⇒ Object
30 31 32 |
# File 'lib/singly/account.rb', line 30 def friends Singly::Friends.new(access_token: access_token) end |
#id(id, params = {}) ⇒ Object
34 35 36 |
# File 'lib/singly/account.rb', line 34 def id(id, params={}) Singly::Id.new(params.merge(access_token: access_token, id: id)) end |
#merge(source) ⇒ Object
Shortcut to Singly.auth.merge(source: <source>, dest: <dest>) where <dest> is always this account’s access_token.
52 53 54 |
# File 'lib/singly/account.rb', line 52 def merge(source) Singly.auth.merge(source: source, dest: access_token) end |
#profile ⇒ Object
14 15 16 |
# File 'lib/singly/account.rb', line 14 def profile Singly::Profile.new(access_token: access_token) end |
#profiles(params = {}) ⇒ Object
18 19 20 |
# File 'lib/singly/account.rb', line 18 def profiles(params={}) Singly::Profiles.new(params.merge(access_token: access_token)) end |
#proxy ⇒ Object
38 39 40 |
# File 'lib/singly/account.rb', line 38 def proxy Singly::Proxy.new(access_token) end |