elibom 0.4.0 → 0.5.0
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 +14 -6
- data/lib/elibom/client.rb +145 -0
- data/lib/elibom.rb +13 -129
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmViYjhiNDg0MWQwZmI4NzdjNDhiZWI2NTA4OThiYTBmMGI2MjRjZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGFjZDdhYjM0OTJhNGYwMGM5NjU5MjMwOTI4MTY1NDYyYjc1MWM3Yg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDU2YTc3MDNlZjQyOGExNDQwZmNiNjJiMGFjMTUzMjk2NGJmN2ZjNDVmZDhl
|
10
|
+
ODM4NmE2NWMwNmRjZmFmNmRmODZhMDdlYTIyMzg5NWI0MTRkMDczOWJiY2Zh
|
11
|
+
MDhjZWRhYmNiZDVmYWE5ZTA4OTIyMTNkODEzN2NjNTMwNWNlM2I=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGViYjhiZDEyMzQ1Y2UzNWMxNmZmNTU4ZGQyYjU0NTlkZjZhMTEwNDU3Mjli
|
14
|
+
OGQxODc5ODU5NWI3NjRlNTk1MmE5NTgyMDMwMzBiYzc2ZjdiNmYyZTkxMmEz
|
15
|
+
Zjc1OTVkOGFmODZkN2Y3ZjY4ZjU1MDFkM2M2N2RiZmZmNTcyNTc=
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Elibom
|
6
|
+
|
7
|
+
class Client
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@host = options[:host] || "https://www.elibom.com"
|
11
|
+
@user = options[:user]
|
12
|
+
@api_password = options[:api_password]
|
13
|
+
|
14
|
+
raise ArgumentError, "Missing key ':user'" if @user.nil? || @user.empty?
|
15
|
+
raise ArgumentError, "Missing key ':api_password'" if @api_password.nil? || @api_password.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_message(args={})
|
19
|
+
body = {}
|
20
|
+
|
21
|
+
required_args = [:to, :text]
|
22
|
+
required_args.each do |arg|
|
23
|
+
raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
|
24
|
+
body[arg] = args[arg]
|
25
|
+
end
|
26
|
+
|
27
|
+
post '/messages', body
|
28
|
+
end
|
29
|
+
|
30
|
+
def schedule_message(args={})
|
31
|
+
body = {}
|
32
|
+
|
33
|
+
required_args = [:to, :text]
|
34
|
+
required_args.each do |arg|
|
35
|
+
raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
|
36
|
+
body[arg] = args[arg]
|
37
|
+
end
|
38
|
+
|
39
|
+
raise ArgumentError, "Missing key ':schedule_date'" if args[:schedule_date].nil?
|
40
|
+
raise ArgumentError, "Invalid argument ':schedule_date'" unless args[:schedule_date].respond_to?('strftime')
|
41
|
+
|
42
|
+
body['scheduleDate'] = args[:schedule_date].strftime('%Y-%m-%d %H:%M')
|
43
|
+
|
44
|
+
post '/messages', body
|
45
|
+
end
|
46
|
+
|
47
|
+
def messages(delivery_id)
|
48
|
+
raise ArgumentError, "'delivery_id' cannot be nil or empty" if delivery_id.nil? || delivery_id.empty?
|
49
|
+
get "/messages/#{delivery_id}"
|
50
|
+
end
|
51
|
+
alias :list_messages :messages
|
52
|
+
|
53
|
+
def scheduled
|
54
|
+
get "/schedules/scheduled"
|
55
|
+
end
|
56
|
+
alias :list_scheduled_messages :scheduled
|
57
|
+
alias :schedules :scheduled
|
58
|
+
alias :list_schedules :scheduled
|
59
|
+
|
60
|
+
def show_schedule(schedule_id)
|
61
|
+
raise ArgumentError, "'schedule_id' cannot be nil" if schedule_id.nil?
|
62
|
+
get "/schedules/#{schedule_id}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def cancel_schedule(schedule_id)
|
66
|
+
raise ArgumentError, "'schedule_id' cannot be nil" if schedule_id.nil?
|
67
|
+
delete "/schedules/#{schedule_id}"
|
68
|
+
end
|
69
|
+
alias :unschedule :cancel_schedule
|
70
|
+
|
71
|
+
def users
|
72
|
+
get "/users"
|
73
|
+
end
|
74
|
+
alias :list_users :users
|
75
|
+
|
76
|
+
def show_user(user_id)
|
77
|
+
raise ArgumentError, "'user_id' cannot be nil" if user_id.nil?
|
78
|
+
get "/users/#{user_id}"
|
79
|
+
end
|
80
|
+
alias :user :show_user
|
81
|
+
|
82
|
+
def show_account
|
83
|
+
get '/account'
|
84
|
+
end
|
85
|
+
alias :account :show_account
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def get(resource)
|
90
|
+
uri = URI.parse("#{@host}#{resource}")
|
91
|
+
http = get_http(uri)
|
92
|
+
|
93
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
94
|
+
request.basic_auth @user, @api_password
|
95
|
+
request['Accept'] = 'application/json'
|
96
|
+
|
97
|
+
response = http.request(request)
|
98
|
+
parse_json_response(response)
|
99
|
+
end
|
100
|
+
|
101
|
+
def post(resource, body)
|
102
|
+
uri = URI.parse("#{@host}#{resource}")
|
103
|
+
http = get_http(uri)
|
104
|
+
|
105
|
+
request = Net::HTTP::Post.new(uri.path)
|
106
|
+
request.basic_auth @user, @api_password
|
107
|
+
request['Content-Type'] = 'application/json'
|
108
|
+
request['Accept'] = 'application/json'
|
109
|
+
request.body = body.to_json
|
110
|
+
|
111
|
+
response = http.request(request)
|
112
|
+
parse_json_response(response)
|
113
|
+
end
|
114
|
+
|
115
|
+
def delete(resource)
|
116
|
+
uri = URI.parse("#{@host}#{resource}")
|
117
|
+
http = get_http(uri)
|
118
|
+
|
119
|
+
request = Net::HTTP::Delete.new(uri.path)
|
120
|
+
request.basic_auth @user, @api_password
|
121
|
+
|
122
|
+
http.request(request)
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_http(uri)
|
126
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
127
|
+
if uri.scheme == 'https'
|
128
|
+
http.use_ssl = true
|
129
|
+
end
|
130
|
+
|
131
|
+
return http
|
132
|
+
end
|
133
|
+
|
134
|
+
def parse_json_response(response)
|
135
|
+
case response
|
136
|
+
when Net::HTTPSuccess
|
137
|
+
JSON.parse(response.body)
|
138
|
+
else
|
139
|
+
response.error!
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
data/lib/elibom.rb
CHANGED
@@ -1,142 +1,26 @@
|
|
1
|
-
require '
|
2
|
-
require 'net/https'
|
3
|
-
require 'json'
|
1
|
+
require File.expand_path('elibom/client.rb', File.dirname(__FILE__))
|
4
2
|
|
5
3
|
# Ruby client of the Elibom API
|
6
4
|
module Elibom
|
7
5
|
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
@host = options[:host] || "https://www.elibom.com"
|
12
|
-
@user = options[:user]
|
13
|
-
@api_password = options[:api_password]
|
14
|
-
|
15
|
-
raise ArgumentError, "Missing key ':user'" if @user.nil? || @user.empty?
|
16
|
-
raise ArgumentError, "Missing key ':api_password'" if @api_password.nil? || @api_password.empty?
|
17
|
-
end
|
18
|
-
|
19
|
-
def send_message(args={})
|
20
|
-
body = {}
|
21
|
-
|
22
|
-
required_args = [:to, :text]
|
23
|
-
required_args.each do |arg|
|
24
|
-
raise ArgumentError, "Missing key ':#{arg}'" if args[arg].nil?
|
25
|
-
body[arg] = args[arg]
|
26
|
-
end
|
27
|
-
|
28
|
-
post '/messages', body
|
29
|
-
end
|
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
|
-
|
49
|
-
def messages(delivery_id)
|
50
|
-
raise ArgumentError, "'delivery_id' cannot be nil or empty" if delivery_id.nil? || delivery_id.empty?
|
51
|
-
get "/messages/#{delivery_id}"
|
52
|
-
end
|
53
|
-
alias :list_messages :messages
|
54
|
-
|
55
|
-
def scheduled
|
56
|
-
get "/schedules/scheduled"
|
6
|
+
class << self
|
7
|
+
def configure(options={})
|
8
|
+
@client = Elibom::Client.new(options)
|
57
9
|
end
|
58
|
-
alias :list_scheduled_messages :scheduled
|
59
|
-
alias :schedules :scheduled
|
60
|
-
alias :list_schedules :scheduled
|
61
10
|
|
62
|
-
def
|
63
|
-
raise
|
64
|
-
|
11
|
+
def method_missing(method_name, *args, &block)
|
12
|
+
raise RuntimeError, "Please call Elibom.configure(:user => '...', :api_password => '...') first" if @client.nil?
|
13
|
+
@client.send(method_name, *args, &block)
|
65
14
|
end
|
66
15
|
|
67
|
-
def
|
68
|
-
raise
|
69
|
-
|
16
|
+
def respond_to_missing?(method_name, include_private=false)
|
17
|
+
raise RuntimeError, "Please call Elibom.configure(:user => '...', :api_password => '...') first" if @client.nil?
|
18
|
+
@client.respond_to?(method_name, include_private)
|
70
19
|
end
|
71
|
-
alias :unschedule :cancel_schedule
|
72
20
|
|
73
|
-
def
|
74
|
-
|
21
|
+
def reset!
|
22
|
+
@client = nil
|
75
23
|
end
|
76
|
-
|
77
|
-
def user(user_id)
|
78
|
-
raise ArgumentError, "'user_id' cannot be nil" if user_id.nil?
|
79
|
-
get "/users/#{user_id}"
|
80
|
-
end
|
81
|
-
|
82
|
-
def account
|
83
|
-
get '/account'
|
84
|
-
end
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def get(resource)
|
89
|
-
uri = URI.parse("#{@host}#{resource}")
|
90
|
-
http = get_http(uri)
|
91
|
-
|
92
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
93
|
-
request.basic_auth @user, @api_password
|
94
|
-
request['Accept'] = 'application/json'
|
95
|
-
|
96
|
-
response = http.request(request)
|
97
|
-
parse_json_response(response)
|
98
|
-
end
|
99
|
-
|
100
|
-
def post(resource, body)
|
101
|
-
uri = URI.parse("#{@host}#{resource}")
|
102
|
-
http = get_http(uri)
|
103
|
-
|
104
|
-
request = Net::HTTP::Post.new(uri.path)
|
105
|
-
request.basic_auth @user, @api_password
|
106
|
-
request['Content-Type'] = 'application/json'
|
107
|
-
request['Accept'] = 'application/json'
|
108
|
-
request.body = body.to_json
|
109
|
-
|
110
|
-
response = http.request(request)
|
111
|
-
parse_json_response(response)
|
112
|
-
end
|
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)
|
134
|
-
case response
|
135
|
-
when Net::HTTPSuccess
|
136
|
-
JSON.parse(response.body)
|
137
|
-
else
|
138
|
-
response.error!
|
139
|
-
end
|
140
|
-
end
|
141
24
|
end
|
25
|
+
|
142
26
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elibom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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-08-
|
11
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: A client of the Elibom API
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- lib/elibom.rb
|
34
|
+
- lib/elibom/client.rb
|
34
35
|
homepage: http://rubygems.org/gems/elibom
|
35
36
|
licenses: []
|
36
37
|
metadata: {}
|
@@ -40,17 +41,17 @@ require_paths:
|
|
40
41
|
- lib
|
41
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
43
|
requirements:
|
43
|
-
- - '>='
|
44
|
+
- - ! '>='
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
48
|
requirements:
|
48
|
-
- - '>='
|
49
|
+
- - ! '>='
|
49
50
|
- !ruby/object:Gem::Version
|
50
51
|
version: '0'
|
51
52
|
requirements: []
|
52
53
|
rubyforge_project:
|
53
|
-
rubygems_version: 2.0.
|
54
|
+
rubygems_version: 2.0.5
|
54
55
|
signing_key:
|
55
56
|
specification_version: 4
|
56
57
|
summary: Elibom API client
|