class Mention::Account
Attributes
access_token[R]
account_id[R]
Public Class Methods
new(credentials)
click to toggle source
# File lib/mention/account.rb, line 3 def initialize(credentials) @account_id = credentials.fetch(:account_id) @access_token = credentials.fetch(:access_token) end
Public Instance Methods
add(alert)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/mention/account.rb, line 29 def created_at Time.parse(account_info['account']['created_at']) end
email()
click to toggle source
# File lib/mention/account.rb, line 25 def email account_info['account']['email'] end
fetch_mentions(alert, params = {})
click to toggle source
# 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()
click to toggle source
# File lib/mention/account.rb, line 21 def id account_info['account']['id'] end
name()
click to toggle source
# File lib/mention/account.rb, line 17 def name account_info['account']['name'] end
remove_alert(alert, share)
click to toggle source
# 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 = {})
click to toggle source
# 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
Private Instance Methods
account_info()
click to toggle source
# File lib/mention/account.rb, line 64 def account_info @account_info ||= JSON.parse(resource.get) end
resource()
click to toggle source
# File lib/mention/account.rb, line 59 def resource @resource ||= RestClient::Resource.new("https://api.mention.net/api/accounts/#{account_id}", headers: {'Authorization' => "Bearer #{access_token}", "Accept" => "application/json"}) end