Class: Apsis

Inherits:
Object
  • Object
show all
Defined in:
lib/apsis.rb,
lib/apsis/version.rb

Constant Summary collapse

ApsisError =
Class.new(StandardError)
VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, default_parameters = {}) ⇒ Apsis

Returns a new instance of Apsis.



8
9
10
11
12
13
14
15
16
# File 'lib/apsis.rb', line 8

def initialize(api_key = nil, default_parameters = {})
  @api_key = api_key || ENV['APSIS_API_KEY']

  @conn = Faraday.new(
    url:      'https://se.api.anpdm.com/v1/',
    ssl:      { verify: false },
    headers:  { accept: 'application/json' })
  @conn.basic_auth(@api_key, '')
end

Instance Method Details

#call(endpoint, params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/apsis.rb', line 18

def call(endpoint, params)
  response = @conn.post do |req|
    req.url endpoint
    req.headers['Content-Type'] = 'application/json'
    req.body = params.to_json
  end
  unless response.status == 200
    raise ApsisError.new("Apsis API Error: #{response.body} (status code #{response.status})")
  end
  JSON.parse response.body
end

#create_subscribers(mailinglist_id, subscribers = []) ⇒ Object



30
31
32
# File 'lib/apsis.rb', line 30

def create_subscribers(mailinglist_id, subscribers = [])
  call("subscribers/mailinglist/#{mailinglist_id}/queue", subscribers)
end