Class: Skipio
- Inherits:
-
Object
- Object
- Skipio
- Defined in:
- lib/skipio.rb
Constant Summary collapse
- API_SERVER =
'https://stage.skipio.com'
Instance Method Summary collapse
-
#contact_list(params = nil) ⇒ Object
params = { page: 1, per: 10 }.
-
#find_contact(contact_id) ⇒ Object
contact_id = Contact#id.
-
#initialize(options) ⇒ Skipio
constructor
A new instance of Skipio.
-
#process_by_url(url, action, options = {}) ⇒ Object
action = :get / :post / :put url = ‘v1/contacts’ options = { params: { Hash: parameters }, json: { Hash: json } }.
- #request_parameters(request_parameters) ⇒ Object
-
#send_message(params = {}) ⇒ Object
params = { recipients: ‘Comma Separated User UUID’, message: ‘body message’ }.
Constructor Details
#initialize(options) ⇒ Skipio
Returns a new instance of Skipio.
10 11 12 |
# File 'lib/skipio.rb', line 10 def initialize() @token = [: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, = {}) uri = URI.parse("#{API_SERVER}/api/#{url}?token=#{@token}&#{[:params]}") if action == :get response = Net::HTTP.get(uri) elsif action == :post json_data = [: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 (params = {}) url = 'v2/messages' json_data = = { json: json_data } response = process_by_url(url, action, ) JSON.parse(response.body) end |