Class: Mention::Account
- Inherits:
-
Object
- Object
- Mention::Account
- Defined in:
- lib/mention/account.rb
Instance Method Summary collapse
- #add(alert) ⇒ Object
- #alerts ⇒ Object
- #created_at ⇒ Object
- #email ⇒ Object
- #fetch_mentions(alert, params = {}) ⇒ Object
- #id ⇒ Object
-
#initialize(credentials) ⇒ Account
constructor
A new instance of Account.
- #name ⇒ Object
- #remove_alert(alert, share) ⇒ Object
- #update_mention_attr(alert, mention, attributes = {}) ⇒ Object
Constructor Details
#initialize(credentials) ⇒ Account
Returns a new instance of Account.
3 4 5 6 |
# File 'lib/mention/account.rb', line 3 def initialize(credentials) @account_id = credentials.fetch(:account_id) @access_token = credentials.fetch(:access_token) end |
Instance Method Details
#add(alert) ⇒ Object
33 34 35 36 37 |
# File 'lib/mention/account.rb', line 33 def add(alert) creator = AlertCreator.new(resource, alert) @alerts = nil if creator.valid? creator.created_alert end |
#alerts ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/mention/account.rb', line 8 def alerts @alerts ||= begin raw_data = JSON.parse(resource['alerts'].get) raw_data['alerts'].map do |hash| Alert.new(hash) end end end |
#created_at ⇒ Object
29 30 31 |
# File 'lib/mention/account.rb', line 29 def created_at Time.parse(account_info['account']['created_at']) end |
#email ⇒ Object
25 26 27 |
# File 'lib/mention/account.rb', line 25 def email account_info['account']['email'] end |
#fetch_mentions(alert, params = {}) ⇒ Object
43 44 45 46 |
# File 'lib/mention/account.rb', line 43 def fetch_mentions(alert, params = {}) raw_data = JSON.parse(resource["/alerts/#{alert.id}/mentions"].get params: params) MentionList.new(raw_data) end |
#id ⇒ Object
21 22 23 |
# File 'lib/mention/account.rb', line 21 def id account_info['account']['id'] end |
#name ⇒ Object
17 18 19 |
# File 'lib/mention/account.rb', line 17 def name account_info['account']['name'] end |
#remove_alert(alert, share) ⇒ Object
39 40 41 |
# File 'lib/mention/account.rb', line 39 def remove_alert(alert, share) resource["/alerts/#{alert.id}/shares/#{share.id}"].delete end |
#update_mention_attr(alert, mention, attributes = {}) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/mention/account.rb', line 48 def update_mention_attr(alert, mention, attributes = {}) headers = {'Content-Type' => 'application/json'} payload = attributes.to_json raw_data = JSON.parse(resource["/alerts/#{alert.id}/mentions/#{mention.id}"].put(payload, headers)) Mention.new(raw_data['mention']) end |