Class: Mention::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/mention/account.rb

Instance Method Summary collapse

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

#alertsObject



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_atObject



29
30
31
# File 'lib/mention/account.rb', line 29

def created_at
  Time.parse(['account']['created_at'])
end

#emailObject



25
26
27
# File 'lib/mention/account.rb', line 25

def email
  ['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

#idObject



21
22
23
# File 'lib/mention/account.rb', line 21

def id
  ['account']['id']
end

#nameObject



17
18
19
# File 'lib/mention/account.rb', line 17

def name
  ['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