Class: Skipio

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

Constant Summary collapse

API_SERVER =
'https://stage.skipio.com'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Skipio

Returns a new instance of Skipio.



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

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

Instance Method Details

#contact_list(params = nil) ⇒ Object

params = { page: 1, per: 10 }



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

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



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

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 } }



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

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



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

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’ }



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

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