elibom 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/elibom.rb +67 -22
- 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: 97ee65d4886bff782366ba4c39a1c9f3259e3959
|
4
|
+
data.tar.gz: a9c14c64658c18a26ab356ba3c350e2b40b45f43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75063201358998322c5e9d35652cf829ab0fe0d775c9e2887872d28a780623a222a2ddba0af4aaf337f472a7962dd125c1473190eb24c0960dba73a9f7ffb3ce
|
7
|
+
data.tar.gz: e2c438bf38fa1acb7aec52739cd55a88e7a419a51c4fce5db3772ce0d6e10d85c827e7eff397267e7d866b2de1a16fc8ca4f51c6c65ba0d474e53559855639be
|
data/lib/elibom.rb
CHANGED
@@ -19,7 +19,7 @@ module Elibom
|
|
19
19
|
def send_message(args={})
|
20
20
|
body = {}
|
21
21
|
|
22
|
-
required_args = [:
|
22
|
+
required_args = [:to, :text]
|
23
23
|
required_args.each do |arg|
|
24
24
|
raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
|
25
25
|
body[arg] = args[arg]
|
@@ -28,12 +28,52 @@ module Elibom
|
|
28
28
|
post '/messages', body
|
29
29
|
end
|
30
30
|
|
31
|
+
def schedule_message(args={})
|
32
|
+
body = {}
|
33
|
+
|
34
|
+
required_args = [:to, :text]
|
35
|
+
required_args.each do |arg|
|
36
|
+
raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
|
37
|
+
body[arg] = args[arg]
|
38
|
+
end
|
39
|
+
|
40
|
+
raise ArgumentError, "Missing key ':schedule_date'" if args[:schedule_date].nil?
|
41
|
+
raise ArgumentError, "Invalid argument ':schedule_date'" unless args[:schedule_date].respond_to?('strftime')
|
42
|
+
|
43
|
+
body['scheduleDate'] = args[:schedule_date].strftime('%Y-%m-%d %H:%M')
|
44
|
+
puts body
|
45
|
+
|
46
|
+
post '/messages', body
|
47
|
+
end
|
48
|
+
|
31
49
|
def messages(delivery_id)
|
32
50
|
raise ArgumentError, "'delivery_id' cannot be nil or empty" if delivery_id.nil? || delivery_id.empty?
|
33
51
|
get "/messages/#{delivery_id}"
|
34
52
|
end
|
35
53
|
alias :list_messages :messages
|
36
54
|
|
55
|
+
def scheduled
|
56
|
+
get "/schedules/scheduled"
|
57
|
+
end
|
58
|
+
alias :list_scheduled_messages :scheduled
|
59
|
+
alias :schedules :scheduled
|
60
|
+
alias :list_schedules :scheduled
|
61
|
+
|
62
|
+
def schedule(schedule_id)
|
63
|
+
raise ArgumentError, "'schedule_id' cannot be nil" if schedule_id.nil?
|
64
|
+
get "/schedules/#{schedule_id}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def cancel_schedule(schedule_id)
|
68
|
+
raise ArgumentError, "'schedule_id' cannot be nil" if schedule_id.nil?
|
69
|
+
delete "/schedules/#{schedule_id}"
|
70
|
+
end
|
71
|
+
alias :unschedule :cancel_schedule
|
72
|
+
|
73
|
+
def users
|
74
|
+
get "/users"
|
75
|
+
end
|
76
|
+
|
37
77
|
def user(user_id)
|
38
78
|
raise ArgumentError, "'user_id' cannot be nil" if user_id.nil?
|
39
79
|
get "/users/#{user_id}"
|
@@ -47,35 +87,19 @@ module Elibom
|
|
47
87
|
|
48
88
|
def get(resource)
|
49
89
|
uri = URI.parse("#{@host}#{resource}")
|
50
|
-
http =
|
51
|
-
|
52
|
-
if uri.scheme == 'https'
|
53
|
-
http.use_ssl = true
|
54
|
-
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
55
|
-
end
|
90
|
+
http = get_http(uri)
|
56
91
|
|
57
92
|
request = Net::HTTP::Get.new(uri.request_uri)
|
58
93
|
request.basic_auth @user, @api_password
|
59
94
|
request['Accept'] = 'application/json'
|
60
95
|
|
61
96
|
response = http.request(request)
|
62
|
-
|
63
|
-
case response
|
64
|
-
when Net::HTTPSuccess
|
65
|
-
JSON.parse(response.body)
|
66
|
-
else
|
67
|
-
response.error!
|
68
|
-
end
|
97
|
+
parse_json_response(response)
|
69
98
|
end
|
70
99
|
|
71
100
|
def post(resource, body)
|
72
101
|
uri = URI.parse("#{@host}#{resource}")
|
73
|
-
http =
|
74
|
-
|
75
|
-
if uri.scheme == 'https'
|
76
|
-
http.use_ssl = true
|
77
|
-
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
78
|
-
end
|
102
|
+
http = get_http(uri)
|
79
103
|
|
80
104
|
request = Net::HTTP::Post.new(uri.path)
|
81
105
|
request.basic_auth @user, @api_password
|
@@ -84,7 +108,29 @@ module Elibom
|
|
84
108
|
request.body = body.to_json
|
85
109
|
|
86
110
|
response = http.request(request)
|
111
|
+
parse_json_response(response)
|
112
|
+
end
|
87
113
|
|
114
|
+
def delete(resource)
|
115
|
+
uri = URI.parse("#{@host}#{resource}")
|
116
|
+
http = get_http(uri)
|
117
|
+
|
118
|
+
request = Net::HTTP::Delete.new(uri.path)
|
119
|
+
request.basic_auth @user, @api_password
|
120
|
+
|
121
|
+
http.request(request)
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_http(uri)
|
125
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
126
|
+
if uri.scheme == 'https'
|
127
|
+
http.use_ssl = true
|
128
|
+
end
|
129
|
+
|
130
|
+
return http
|
131
|
+
end
|
132
|
+
|
133
|
+
def parse_json_response(response)
|
88
134
|
case response
|
89
135
|
when Net::HTTPSuccess
|
90
136
|
JSON.parse(response.body)
|
@@ -92,6 +138,5 @@ module Elibom
|
|
92
138
|
response.error!
|
93
139
|
end
|
94
140
|
end
|
95
|
-
|
96
141
|
end
|
97
|
-
end
|
142
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elibom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- German Escobar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|