Class: Repro::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/repro/api/client.rb,
lib/repro/api/client/version.rb

Constant Summary collapse

API_VERSION =
'v1'.freeze
API_ENDPOINT =
"https://marketing.repro.io/#{API_VERSION}".freeze
VERSION =
"0.3.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, opts = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
# File 'lib/repro/api/client.rb', line 17

def initialize(token, opts = {})
  @options = opts.merge(token: token, method: 'post')
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/repro/api/client.rb', line 15

def options
  @options
end

Instance Method Details

#endpointObject



47
48
49
# File 'lib/repro/api/client.rb', line 47

def endpoint
  @options[:endpoint] || API_ENDPOINT
end

#push_deliver(push_id, user_ids, opts = {}) ⇒ Object

/push/:push_id/deliver

Parameters:

  • push_id (String)

    Push ID in Repro

  • user_ids (Array)

    UserIDs to send push notification

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :body (String)

    Message body for push notification. (required)

  • :title (String)

    Title for push notification

  • :badge (Integer)

    Badge number

  • :sound (String)

    Sound file name for notification

  • :url (String)

    Custom url or Deep Link

  • :attachment (Hash)

    Attachment for rich push. Hash must have keys :type and :url.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
# File 'lib/repro/api/client.rb', line 30

def push_deliver(push_id, user_ids, opts = {})
  raise ArgumentError, ':body is required.' unless opts[:body]
  opts[:path] = "/push/#{push_id}/deliver"
  body = { audience: { user_ids: user_ids } }
  body[:notification] = {custom_payload: build_payload(opts)}
  opts[:body] = body
  send_request(opts)
end

#tokenObject



39
40
41
# File 'lib/repro/api/client.rb', line 39

def token
  @options[:token]
end

#user_agentObject



43
44
45
# File 'lib/repro/api/client.rb', line 43

def user_agent
  @options[:user_agent] || "Repro Ruby Client/#{VERSION}"
end