skipio_api 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/skipio.rb +42 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f478a2d2b8dcd89e432cbdf3c3521e6b3f7549e4
|
4
|
+
data.tar.gz: 6de88e39be7daa337f47d0339dde0691cffd277d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9b54cc377da41bd76a9ab4d8fed4d1af60aa3b37afaea0747b2d6565e90b1a7de233fe69af54d3834550abb179282ec1eb1444420cc07e171b0d24edede80f2
|
7
|
+
data.tar.gz: 879e908e5364a986be2c7e501b820d353c841a82e585f77d41c6f2ad6a070f02334c8072864c0697d8975cb442ad2953bbad409d24c78272ee58558202a62530
|
data/lib/skipio.rb
CHANGED
@@ -9,25 +9,29 @@ class Skipio
|
|
9
9
|
|
10
10
|
def initialize(options)
|
11
11
|
@token = options[:token]
|
12
|
-
@params = options[:params]
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
response =
|
14
|
+
# params = { page: 1, per: 10 }
|
15
|
+
def contact_list(params = nil)
|
16
|
+
page_parameters = params || { page: 1, per: 10 }
|
17
|
+
url = 'v2/contacts'
|
18
|
+
response = process_by_url(url, :get, page_parameters)
|
20
19
|
JSON.parse(response)
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
# contact_id = Contact#id
|
23
|
+
def find_contact(contact_id)
|
24
|
+
url = "/v2/contacts/#{contact_id}"
|
25
|
+
response = process_by_url(url, :get)
|
26
|
+
JSON.parse(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# params = { recipients: 'Comma Separated User UUID', message: 'body message' }
|
30
|
+
def send_message(params = {})
|
31
|
+
url = 'v2/messages'
|
25
32
|
json_data = build_json_message_data
|
26
|
-
|
27
|
-
|
28
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'})
|
29
|
-
request.set_form_data(JSON.parse(json_data.to_json))
|
30
|
-
response = http.request(request)
|
33
|
+
options = { json: json_data }
|
34
|
+
response = process_by_url(url, action, options)
|
31
35
|
JSON.parse(response.body)
|
32
36
|
end
|
33
37
|
|
@@ -37,6 +41,31 @@ class Skipio
|
|
37
41
|
uri.query
|
38
42
|
end
|
39
43
|
|
44
|
+
# action = :get / :post / :put
|
45
|
+
# url = 'v1/contacts'
|
46
|
+
# options = { params: { Hash: parameters }, json: { Hash: json } }
|
47
|
+
def process_by_url(url, action, options = {})
|
48
|
+
uri = URI.parse("#{API_SERVER}/api/#{url}?token=#{@token}&#{options[:params]}")
|
49
|
+
if action == :get
|
50
|
+
response = Net::HTTP.get(uri)
|
51
|
+
elsif action == :post
|
52
|
+
json_data = options[:json].to_json
|
53
|
+
response = create_by_url(uri, json_data)
|
54
|
+
end
|
55
|
+
|
56
|
+
response
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def create_by_url(uri, json_data)
|
62
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
63
|
+
http.use_ssl = true
|
64
|
+
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'application/json'})
|
65
|
+
request.set_form_data(JSON.parse(json_data))
|
66
|
+
http.request(request)
|
67
|
+
end
|
68
|
+
|
40
69
|
def build_json_message_data
|
41
70
|
{
|
42
71
|
"recipients": [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skipio_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Psalmuel Aguilar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|