Class: Skipio

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Skipio

Returns a new instance of Skipio.



8
9
10
11
# File 'lib/skipio.rb', line 8

def initialize(options)
  @token = options[:token]
  @api_server = options[:api_server] || :dev
end

Instance Method Details

#api_serverObject



58
59
60
61
62
63
64
# File 'lib/skipio.rb', line 58

def api_server
  if @api_server == :prod
    'https://app.skipio.com'
  elsif :dev
    'https://stage.skipio.com'
  end
end

#contact_list(params = nil) ⇒ Object

params = { page: 1, per: 10 }



14
15
16
17
18
19
# File 'lib/skipio.rb', line 14

def contact_list(params = nil)
  page_parameters = params || { page: 1, per: 10 }
  url = 'v2/contacts'
  response = process_by_url(url, :get, page_parameters)
  JSON.parse(response)
end

#find_contact(contact_id) ⇒ Object

contact_id = Contact#id



22
23
24
25
26
# File 'lib/skipio.rb', line 22

def find_contact(contact_id)
  url = "/v2/contacts/#{contact_id}"
  response = process_by_url(url, :get)
  JSON.parse(response)
end

#process_by_url(url, action, options = {}) ⇒ Object

action = :get / :post / :put url = ‘v1/contacts’ options = { params: { Hash: parameters }, json: { Hash: json } }



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/skipio.rb', line 46

def process_by_url(url, action, options = {})
  uri = URI.parse("#{api_server}/api/#{url}?token=#{@token}&#{options[:params]}")
  if action == :get
    response = Net::HTTP.get(uri)
  elsif action == :post
    json_data = options[:json].to_json
    response = create_by_url(uri, json_data)
  end

  response
end

#request_parameters(request_parameters) ⇒ Object



37
38
39
40
41
# File 'lib/skipio.rb', line 37

def request_parameters(request_parameters)
  uri = Addressable::URI.new
  uri.query_values = request_parameters
  uri.query
end

#send_message(params = {}) ⇒ Object

params = { recipients: ‘Comma Separated User UUID’, message: ‘body message’ }



29
30
31
32
33
34
35
# File 'lib/skipio.rb', line 29

def send_message(params = {})
  url = 'v2/messages'
  json_data = build_json_message_data(params)
  options = { json: json_data }
  response = process_by_url(url, :post, options)
  JSON.parse(response.body)
end