Class: Monzo::FeedItem

Inherits:
Object
  • Object
show all
Defined in:
lib/monzo/feed_item.rb

Overview

Public: The Monzo app is organised around the feed – a

reverse-chronological stream of events. Transactions
are one such feed item, and your application can
create its own feed items to surface relevant information
to the user.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ FeedItem

Public: Initialize a FeedItem.

params - A Hash of feed item parameters.



15
16
17
18
19
20
# File 'lib/monzo/feed_item.rb', line 15

def initialize(params)
  @account_id = params[:account_id]
  @type = params[:type]
  @params = params[:params]
  @url = params[:url]
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



10
11
12
# File 'lib/monzo/feed_item.rb', line 10

def 
  @account_id
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/monzo/feed_item.rb', line 10

def params
  @params
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/monzo/feed_item.rb', line 10

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/monzo/feed_item.rb', line 10

def url
  @url
end

Class Method Details

.create(account_id, type, params, url = nil) ⇒ Object

Public: Create a feed item on a user’s feed.

account_id - The account id to create a feed item for. type - Type of feed item. Currently only basic is supported. params - A Hash of parameters which vary based on type. url - A URL to open when the feed item is tapped.

If no URL is provided, the app will display a fallback
view based on the title & body. (optional)

Returns: An empty Hash.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/monzo/feed_item.rb', line 32

def self.create(, type, params, url = nil)
  client = Monzo.client

  data = {
    "account_id" => ,
    "type" => type,
    "params[title]" => params[:title],
    "params[image_url]" => params[:image_url],
    "params[background_color]" => params[:background_color],
    "params[body_color]" => params[:body_color],
    "params[title_color]" => params[:title_color],
    "params[body]" => params[:body],
    "url" => url
  }
  response = client.post("/feed", data, {})
  JSON.parse(response.body, :symbolize_names => true)
end