Module: Repro::Api::Client

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.1.0"
@@options =
{
  method: 'post'
}

Class Method Summary collapse

Class Method Details

.configure {|@@options| ... } ⇒ Object

Yields:

Raises:

  • (ArgumentError)


27
28
29
30
# File 'lib/repro/api/client.rb', line 27

def self.configure
  raise ArgumentError, 'Block is required.' unless block_given?
  yield @@options
end

.endpointObject



60
61
62
# File 'lib/repro/api/client.rb', line 60

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

.optionsObject



19
20
21
# File 'lib/repro/api/client.rb', line 19

def self.options
  @@options
end

.options=(opts) ⇒ Object



23
24
25
# File 'lib/repro/api/client.rb', line 23

def self.options=(opts)
  @@options = opts
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)


41
42
43
44
45
46
47
48
# File 'lib/repro/api/client.rb', line 41

def self.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



52
53
54
# File 'lib/repro/api/client.rb', line 52

def token
  @@options[:token]
end

.user_agentObject



56
57
58
# File 'lib/repro/api/client.rb', line 56

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