icm-ruby-client 0.0.1
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 +7 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +79 -0
- data/Rakefile +1 -0
- data/examples.rb +142 -0
- data/icm-ruby-client.gemspec +26 -0
- data/lib/icm_ruby_client.rb +73 -0
- data/lib/icm_ruby_client/version.rb +3 -0
- data/test/icm_ruby_client_spec.rb +161 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f65812a1111597a5821cadd3e248d15c0628179d
|
4
|
+
data.tar.gz: 0907cfb8d52453c6bd0a326fa94e3177c9314744
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e224b809488e16d865ffb8103d5baae8ab41d77153cc5e7d09faa9cd2e44e1251ccf5647480b366ab7f46ff5f61fda78640a3155734c93c60a0f687030f531cf
|
7
|
+
data.tar.gz: 675da2017a0fc53ee30cdeea5240cd72469d4ee9904f6ac51687b85147d4ba6bd296a50daea22d3e275175f82eab21a3d8c052448f21b819c39d4653671da15d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Singlewire LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# InformaCast Mobile REST Ruby Client
|
2
|
+
|
3
|
+
A simple, easy to use REST client based on [rest-client](https://github.com/rest-client/rest-client)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Installation should be straight forward:
|
8
|
+
|
9
|
+
```shell
|
10
|
+
gem install icm-ruby-client
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Require the client:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'icm_client'
|
19
|
+
```
|
20
|
+
|
21
|
+
Create an instance of the client:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
icm_client = ICMClient::Client.new('<My Access Token>')
|
25
|
+
```
|
26
|
+
|
27
|
+
Have fun!
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Get first page of users
|
31
|
+
icm_client.users.get
|
32
|
+
|
33
|
+
# Paginate through all users
|
34
|
+
icm_client.users.list.each do |user|
|
35
|
+
puts user
|
36
|
+
end
|
37
|
+
|
38
|
+
# Search for a user named Jim
|
39
|
+
icm_client.users.get(:params => {:limit => 10, :q => 'Jim'})
|
40
|
+
|
41
|
+
# Get a specific user
|
42
|
+
icm_client.users('de7b51a0-5a1e-11e4-ab31-8a1d033dd637').get
|
43
|
+
|
44
|
+
# Get a specific user's devices
|
45
|
+
icm_client.users('de7b51a0-5a1e-11e4-ab31-8a1d033dd637').devices.get
|
46
|
+
|
47
|
+
# Create a user
|
48
|
+
user = JSON.parse(icm_client.users.post(:name => 'Jim Bob', :email => 'jim.bob@aol.com'))
|
49
|
+
|
50
|
+
# Update the created user
|
51
|
+
icm_client.users(user['id']).put(:name => 'Jim Bob The Second')
|
52
|
+
|
53
|
+
# Delete the updated user
|
54
|
+
icm_client.users(user['id']).delete
|
55
|
+
```
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The MIT License (MIT)
|
60
|
+
|
61
|
+
Copyright (c) 2015 Singlewire LLC
|
62
|
+
|
63
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
64
|
+
of this software and associated documentation files (the "Software"), to deal
|
65
|
+
in the Software without restriction, including without limitation the rights
|
66
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
67
|
+
copies of the Software, and to permit persons to whom the Software is
|
68
|
+
furnished to do so, subject to the following conditions:
|
69
|
+
|
70
|
+
The above copyright notice and this permission notice shall be included in all
|
71
|
+
copies or substantial portions of the Software.
|
72
|
+
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
74
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
75
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
76
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
77
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
78
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
79
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/examples.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'icm_ruby_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
token = '3F24FYHHIUI6HPEMZAVBIT7LC64DAFJA45DRDY5VIHECUFCP5MLXADABFHMBE5HWLWXKQTSONPEIC7CIRDOZITGGTCS6R3A3KJFG46I='
|
5
|
+
rest_client_opt = {}
|
6
|
+
icm_client = ICMClient::Client.new(token, rest_client_opt, 'https://my-server-override.com/api/v1-DEV')
|
7
|
+
|
8
|
+
#print icm_client.users.get
|
9
|
+
|
10
|
+
#puts JSON.pretty_generate(JSON.parse(icm_client.session.get))
|
11
|
+
#puts JSON.parse(icm_client.session.get)
|
12
|
+
|
13
|
+
# begin
|
14
|
+
# puts icm_client.users.post(
|
15
|
+
# :name => 'Craig Smith',
|
16
|
+
# :email => 'craig.smith@acme.com')
|
17
|
+
# rescue => e
|
18
|
+
# p e
|
19
|
+
# p e.response
|
20
|
+
# end
|
21
|
+
|
22
|
+
def getting_started_example(icm_client)
|
23
|
+
puts "Creating user"
|
24
|
+
begin
|
25
|
+
user = JSON.parse(
|
26
|
+
icm_client.users.post(
|
27
|
+
:name => 'Craig Smith',
|
28
|
+
:email => 'craig.smith@acme.com'))
|
29
|
+
puts JSON.pretty_generate(user)
|
30
|
+
|
31
|
+
puts "Creating distribution list"
|
32
|
+
list = JSON.parse(
|
33
|
+
icm_client.distribution_lists.post(
|
34
|
+
:name => 'To Just Craig Smith'))
|
35
|
+
puts JSON.pretty_generate(list)
|
36
|
+
|
37
|
+
puts "Subscribing user"
|
38
|
+
sub = JSON.parse(
|
39
|
+
icm_client.users(user['id']).subscriptions.
|
40
|
+
post(:distributionListId => list['id']))
|
41
|
+
puts JSON.pretty_generate(sub)
|
42
|
+
|
43
|
+
puts "Registering user device"
|
44
|
+
reg = JSON.parse(
|
45
|
+
icm_client.users(user['id']).devices.post(
|
46
|
+
:type => "Android",
|
47
|
+
:name => "Android Nexus Fire 2",
|
48
|
+
:deviceIdentifier => "APA91bFpOikKATC523g5Z_4-1puPNa_oE8t1sTzEwlfWKE0jFH-TvjAmFL_1ZkSCq7VGNA6dGn3jDQ5BsdZAf"))
|
49
|
+
puts JSON.pretty_generate(reg)
|
50
|
+
|
51
|
+
puts "Creating confirmation request"
|
52
|
+
conf_req = JSON.parse(
|
53
|
+
icm_client.confirmation_requests.post(
|
54
|
+
:name => "Are you there?",
|
55
|
+
:options => ["Yes", "No"]))
|
56
|
+
puts JSON.pretty_generate(conf_req)
|
57
|
+
|
58
|
+
puts "Creating message template"
|
59
|
+
template = JSON.parse(
|
60
|
+
icm_client.message_templates.post(
|
61
|
+
:name => "For Craig Smith Only",
|
62
|
+
:subject => "Hello Craig. Are you there?",
|
63
|
+
:body => "Please confirm you are present.",
|
64
|
+
:confirmationRequestId => conf_req['id'],
|
65
|
+
:distributionListIds => [list['id']]))
|
66
|
+
|
67
|
+
puts "Sending notification"
|
68
|
+
sent = JSON.parse(
|
69
|
+
icm_client.notifications.post(
|
70
|
+
:messageTemplateId => template['id']))
|
71
|
+
puts JSON.pretty_generate(sent)
|
72
|
+
|
73
|
+
puts "Cleaning up..."
|
74
|
+
|
75
|
+
puts icm_client.message_templates(template['id']).delete;
|
76
|
+
puts icm_client.confirmation_requests(conf_req['id']).delete;
|
77
|
+
puts icm_client.distribution_lists(list['id']).delete;
|
78
|
+
puts icm_client.users(user['id']).delete;
|
79
|
+
rescue => e
|
80
|
+
p e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def list_users_example(icm_client)
|
85
|
+
users = icm_client.users.list
|
86
|
+
users.each do |user|
|
87
|
+
puts
|
88
|
+
puts "-----"
|
89
|
+
puts JSON.pretty_generate(user)
|
90
|
+
puts "*********************"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def user_crud_example(icm_client)
|
95
|
+
begin
|
96
|
+
user = JSON.parse(
|
97
|
+
icm_client.users.post(
|
98
|
+
:name => 'Craig Smith',
|
99
|
+
:email => 'craig.smith@acme.com',
|
100
|
+
:lock => {
|
101
|
+
:start => '2015-04-16T14:50:23.126+0000',
|
102
|
+
:end => '2015-09-16T14:50:23.126+0000' }))
|
103
|
+
puts JSON.pretty_generate(user)
|
104
|
+
|
105
|
+
puts "vvvvvvvv"
|
106
|
+
puts JSON.pretty_generate(JSON.parse(
|
107
|
+
icm_client.users(user['id']).put(
|
108
|
+
:name => 'Craig Jacob Smith')))
|
109
|
+
puts "^^^^^^^^"
|
110
|
+
|
111
|
+
puts JSON.parse(icm_client.users(user['id']).delete)
|
112
|
+
rescue => e
|
113
|
+
p e
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def user_subscription_example(icm_client)
|
118
|
+
# Shows how to do lazy enumeration of results, so output differs slightly raw
|
119
|
+
# shared example below.
|
120
|
+
begin
|
121
|
+
subs = icm_client.users('8fa95070-fd3c-11e3-9c2f-c82a144feb17').subscriptions.list
|
122
|
+
puts "Subscription count: #{subs.count}."
|
123
|
+
subs.each do |sub|
|
124
|
+
puts JSON.pretty_generate(sub)
|
125
|
+
end
|
126
|
+
|
127
|
+
sub = JSON.parse(icm_client.users('8fa95070-fd3c-11e3-9c2f-c82a144feb17').subscriptions('8fb3fed0-fd3c-11e3-9c2f-c82a144feb17').get)
|
128
|
+
puts JSON.pretty_generate(sub)
|
129
|
+
|
130
|
+
rescue => e
|
131
|
+
p e
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
#list_users_example(icm_client)
|
138
|
+
#user = JSON.parse(icm_client.users('8fa95070-fd3c-11e3-9c2f-c82a144feb17').get)
|
139
|
+
#puts JSON.pretty_generate(user)
|
140
|
+
#getting_started_example icm_client
|
141
|
+
|
142
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'icm_ruby_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'icm-ruby-client'
|
8
|
+
spec.version = ICMClient::VERSION
|
9
|
+
spec.authors = ['Vincent Pizzo']
|
10
|
+
spec.email = %w(vincent.pizzo@singlewire.com)
|
11
|
+
spec.description = %q{A simple ruby client for InformaCast Mobile.}
|
12
|
+
spec.summary = %q{A simple ruby client for InformaCast Mobile based on the popular rest-client.}
|
13
|
+
spec.homepage = 'https://github.com/singlewire/icm-ruby-client'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = %w(lib)
|
19
|
+
|
20
|
+
spec.add_dependency 'rest-client', '~> 1.7.3', '>= 1.7.3'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'webmock', '~> 1.21.0', '>= 1.21.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
|
24
|
+
|
25
|
+
spec.required_ruby_version = '>= 1.9.3'
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'icm_ruby_client/version'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
# This module provides an entry point for interacting with the InformaCast REST API
|
7
|
+
module ICMClient
|
8
|
+
class Client
|
9
|
+
# Extend forwardable to delegate to RestClient::Resource's get, post, put, delete, head, and options
|
10
|
+
extend Forwardable
|
11
|
+
def_delegators :nested_resource, :get, :post, :put, :delete, :head, :options
|
12
|
+
|
13
|
+
attr_reader :base_url, :access_token, :path
|
14
|
+
|
15
|
+
# The default limit for list/pagination
|
16
|
+
DEFAULT_LIMIT = 100
|
17
|
+
|
18
|
+
# Creates a new instance of an InformaCast Mobile REST client
|
19
|
+
# Params:
|
20
|
+
# +access_token+:: Required argument for interacting with the REST API
|
21
|
+
# +client_options+:: Optional argument for supplying additional options to RestClient.
|
22
|
+
# +base_url+:: Optional argument for overriding the default base base_url. Useful for testing.
|
23
|
+
# +path+:: Optional argument for overriding the base path.
|
24
|
+
# +resource+:: Optional argument for overriding the default RestClient.
|
25
|
+
def initialize(access_token, client_options={}, base_url='https://api.icmobile.singlewire.com/api/v1-DEV', path=nil, resource=nil)
|
26
|
+
@access_token = access_token.freeze or raise ArgumentError, 'must pass :access_token'
|
27
|
+
@base_url = base_url.freeze or raise ArgumentError, 'must pass :base_url'
|
28
|
+
@path = path.freeze
|
29
|
+
@resource = resource || RestClient::Resource.new(base_url, {:headers => {
|
30
|
+
:authorization => "Bearer #{access_token}",
|
31
|
+
:x_client_version => 'RubyClient 0.0.1'
|
32
|
+
}}.merge(client_options || {}))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Provides the magic necessary to chain method calls
|
36
|
+
# ==== Examples
|
37
|
+
# client = ICMClient::Client.new('<My Access Token>')
|
38
|
+
# puts client.users('<User Id>').devices.get
|
39
|
+
def method_missing(symbol, *args)
|
40
|
+
raise ArgumentError, 'only one argument may be provided' if args.length > 1
|
41
|
+
formatted_resource_name = symbol.to_s.gsub('_', '-')
|
42
|
+
resource_id = ("/#{args.first}" unless args.empty?)
|
43
|
+
new_path = "#{@path}/#{formatted_resource_name}#{resource_id}"
|
44
|
+
Client.new(@access_token, nil, @base_url, new_path, @resource)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Builds a lazy enumerator for paging through resources defined in the InformaCast Mobile API
|
48
|
+
def list(*args)
|
49
|
+
args = [{:params => {:limit => DEFAULT_LIMIT}}] if args.empty? or !args.first.respond_to?(:has_key?)
|
50
|
+
args.first[:params] = {:limit => DEFAULT_LIMIT} unless args.first[:params]
|
51
|
+
args.first[:params][:limit] = DEFAULT_LIMIT unless args.first[:params][:limit]
|
52
|
+
next_token = nil
|
53
|
+
Enumerator.new do |y|
|
54
|
+
while true
|
55
|
+
args.first[:params][:start] = next_token if next_token
|
56
|
+
raw_response_str = nested_resource.get(*args)
|
57
|
+
response = JSON.parse(raw_response_str, :symbolize_names => true)
|
58
|
+
resources = response[:data]
|
59
|
+
resources.each { |resource| y.yield resource }
|
60
|
+
next_token = response[:next]
|
61
|
+
break unless next_token
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Grabs a nested resource based on the path for this client
|
69
|
+
def nested_resource
|
70
|
+
@resource[@path]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'icm_ruby_client'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
USER = {:createdAt => '2015-01-12T16:52:47.614+0000',
|
7
|
+
:email => 'a@aol.com',
|
8
|
+
:id => '6fd989e0-9a7b-11e4-a6d1-c22f013130a9',
|
9
|
+
:locations => [],
|
10
|
+
:lock => nil,
|
11
|
+
:name => 'a',
|
12
|
+
:permissions => %w(delete put get),
|
13
|
+
:securityGroups => [],
|
14
|
+
:subscriptions => []}.freeze
|
15
|
+
|
16
|
+
describe ICMClient::Client, '#new' do
|
17
|
+
before(:each) do
|
18
|
+
@client = ICMClient::Client.new('my_access_token')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'Access token must be provided or an exception will be thrown' do
|
22
|
+
expect { ICMClient::Client.new(nil) }.to raise_error ArgumentError
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Should have the proper set of readers and methods assigned' do
|
26
|
+
expect(@client).to be_an_instance_of ICMClient::Client
|
27
|
+
expect(@client.access_token).to eq 'my_access_token'
|
28
|
+
expect(@client.base_url).to eq 'https://api.icmobile.singlewire.com/api/v1-DEV'
|
29
|
+
expect(@client.path).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ICMClient::Client, '#method_missing' do
|
34
|
+
before(:each) do
|
35
|
+
@client = ICMClient::Client.new('my_access_token')
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'Should generate the proper url for first missing method' do
|
39
|
+
expect(@client.users.path).to eq '/users'
|
40
|
+
expect(@client.message_templates.path).to eq '/message-templates'
|
41
|
+
expect(@client.distribution_lists.path).to eq '/distribution-lists'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'Should generate the proper url for nested missing methods' do
|
45
|
+
expect { @client.users('first_arg', 'second_arg') }.to raise_error ArgumentError
|
46
|
+
expect(@client.users('user_id').subscriptions.path).to eq '/users/user_id/subscriptions'
|
47
|
+
expect(@client.message_templates('message_template_id').audio.path).to eq '/message-templates/message_template_id/audio'
|
48
|
+
expect(@client.distribution_lists('distribution_list_id').user_subscriptions.path).to eq '/distribution-lists/distribution_list_id/user-subscriptions'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ICMClient::Client, '#get' do
|
53
|
+
before(:each) do
|
54
|
+
@client = ICMClient::Client.new('my_access_token')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "Raises an exception when the user can't be found" do
|
58
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users/user-id').
|
59
|
+
to_return(:status => 404, :body => '{"status": 404,"message": "Not Found"}')
|
60
|
+
expect { @client.users('user-id').get }.to raise_error RestClient::ResourceNotFound
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'Raises an exception when we receive an unauthorized response' do
|
64
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users/user-id').
|
65
|
+
to_return(:status => 401, :body => '{"type": "unauthorized","status": 401,"message": "Unauthorized"}')
|
66
|
+
expect { @client.users('user-id').get }.to raise_error RestClient::Unauthorized
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'Can get data for an individual user' do
|
70
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users/user-id').
|
71
|
+
to_return(:body => JSON.dump(USER), :status => 200)
|
72
|
+
user = JSON.parse(@client.users('user-id').get, :symbolize_names => true)
|
73
|
+
expect(user).to eq USER
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe ICMClient::Client, '#list' do
|
78
|
+
before(:each) do
|
79
|
+
@client = ICMClient::Client.new('my_access_token')
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'Raises an exception when we receive an unauthorized response' do
|
83
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users?limit=100').
|
84
|
+
to_return(:status => 401, :body => '{"type": "unauthorized","status": 401,"message": "Unauthorized"}')
|
85
|
+
expect { @client.users.list.first }.to raise_error RestClient::Unauthorized
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'Can get an empty page of data' do
|
89
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users?limit=100').
|
90
|
+
to_return(:status => 200, :body => JSON.dump({:total => 0, :next => nil, :previous => nil, :data => []}))
|
91
|
+
users = @client.users.list.to_a
|
92
|
+
expect(users).to be_empty
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'Can get a full page of data' do
|
96
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users?limit=100').
|
97
|
+
to_return(:status => 200, :body => JSON.dump({:total => 1, :next => nil, :previous => nil, :data => [USER]}))
|
98
|
+
users = @client.users.list.to_a
|
99
|
+
expect(users.count).to eq 1
|
100
|
+
expect(users[0]).to eq USER
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'Can get multiple pages of data' do
|
104
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users?limit=1').
|
105
|
+
to_return(:status => 200, :body => JSON.dump({:total => 3, :next => 'first', :previous => nil, :data => [USER]}))
|
106
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users?limit=1&start=first').
|
107
|
+
to_return(:status => 200, :body => JSON.dump({:total => 3, :next => 'second', :previous => 'first', :data => [USER]}))
|
108
|
+
stub_request(:get, 'https://api.icmobile.singlewire.com/api/v1-DEV/users?limit=1&start=second').
|
109
|
+
to_return(:status => 200, :body => JSON.dump({:total => 3, :next => nil, :previous => 'second', :data => [USER]}))
|
110
|
+
users = @client.users.list(:params => {:limit => 1}).to_a
|
111
|
+
expect(users.count).to eq 3
|
112
|
+
users.each do |user|
|
113
|
+
expect(user).to eq USER
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe ICMClient::Client, '#post' do
|
118
|
+
before(:each) do
|
119
|
+
@client = ICMClient::Client.new('my_access_token')
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'Raises an exception when we receive an unauthorized response' do
|
123
|
+
stub_request(:post, 'https://api.icmobile.singlewire.com/api/v1-DEV/users').
|
124
|
+
with(:body => {:name => 'Craig Smith', :email => 'craig.smith@acme.com'}).
|
125
|
+
to_return(:status => 401, :body => '{"type": "unauthorized","status": 401,"message": "Unauthorized"}')
|
126
|
+
expect { @client.users.post(:name => 'Craig Smith', :email => 'craig.smith@acme.com') }.to raise_error RestClient::Unauthorized
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'Creates a new user with the correct data' do
|
130
|
+
stub_request(:post, 'https://api.icmobile.singlewire.com/api/v1-DEV/users').
|
131
|
+
with(:body => {:email => 'a@aol.com', :name => 'a'}).
|
132
|
+
to_return(:status => 200, :body => JSON.dump(USER))
|
133
|
+
created_user = JSON.parse(@client.users.post(:name => 'a', :email => 'a@aol.com'), :symbolize_names => true)
|
134
|
+
expect(created_user).to eq USER
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe ICMClient::Client, '#put' do
|
139
|
+
before(:each) do
|
140
|
+
@client = ICMClient::Client.new('my_access_token')
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'Raises an exception when we receive an unauthorized response' do
|
144
|
+
stub_request(:put, 'https://api.icmobile.singlewire.com/api/v1-DEV/users/user-id').
|
145
|
+
with(:body => {:email => 'craig.smith@acme.com'}).
|
146
|
+
to_return(:status => 401, :body => '{"type": "unauthorized","status": 401,"message": "Unauthorized"}')
|
147
|
+
expect { @client.users('user-id').put(:email => 'craig.smith@acme.com') }.to raise_error RestClient::Unauthorized
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'Creates a new user with the correct data' do
|
151
|
+
temp_user = USER.dup
|
152
|
+
temp_user[:name] = 'a2'
|
153
|
+
stub_request(:put, 'https://api.icmobile.singlewire.com/api/v1-DEV/users/user-id').
|
154
|
+
with(:body => {:name => 'a2'}).
|
155
|
+
to_return(:status => 200, :body => JSON.dump(temp_user))
|
156
|
+
created_user = JSON.parse(@client.users('user-id').put(:name => 'a2'), :symbolize_names => true)
|
157
|
+
expect(created_user).to eq temp_user
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icm-ruby-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincent Pizzo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.3
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.7.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.7.3
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.7.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: webmock
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.21.0
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.21.0
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.21.0
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.21.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.2'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.2.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.2'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.2.0
|
73
|
+
description: A simple ruby client for InformaCast Mobile.
|
74
|
+
email:
|
75
|
+
- vincent.pizzo@singlewire.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- examples.rb
|
86
|
+
- icm-ruby-client.gemspec
|
87
|
+
- lib/icm_ruby_client.rb
|
88
|
+
- lib/icm_ruby_client/version.rb
|
89
|
+
- test/icm_ruby_client_spec.rb
|
90
|
+
homepage: https://github.com/singlewire/icm-ruby-client
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 1.9.3
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: A simple ruby client for InformaCast Mobile based on the popular rest-client.
|
114
|
+
test_files:
|
115
|
+
- test/icm_ruby_client_spec.rb
|
116
|
+
has_rdoc:
|