omni_api 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/OmniApi.gemspec +4 -4
- data/lib/omni_api/factories/user_factory.rb +6 -6
- data/lib/omni_api/resources/oauth2/token.rb +3 -3
- data/lib/omni_api/resources/sms_message.rb +1 -1
- data/lib/omni_api/resources/user_authorized_resource.rb +0 -11
- data/lib/omni_api/version.rb +1 -1
- data/spec/OmniApi/factories/user_factory_spec.rb +39 -0
- data/spec/OmniApi/resources/sms_message_spec.rb +15 -0
- data/spec/OmniApi/resources/user/user_resource_spec.rb +0 -6
- data/spec/OmniApi/resources/user_authorized_resource_spec.rb +0 -6
- data/spec/spec_helper.rb +3 -1
- metadata +30 -8
- data/lib/OmniApi.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2eb1577afa97eb1cc2a58fee25900b59f807f9ac
|
4
|
+
data.tar.gz: 4a9242500eb846d47e9089d7e03fc7e29eb8e491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbf5b72b329db9c4e6c2e16dc41bbcd216f685255daed1154f8fca33c04df4cc6d3c887cba77f79702922d311355915199e0c16ed85ffa72eb3aff5d6d6b59f0
|
7
|
+
data.tar.gz: fe6f2c7534cd5109a60f69e016f2161f46de8eae1a66514978e17fc08c1755bf1bde687099b16f2fac7478063e956763cb991298791d643d93a42b5d865425f7
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omni_api (0.0.
|
5
|
-
activeresource (~> 4.0.0)
|
4
|
+
omni_api (0.0.4)
|
5
|
+
activeresource (~> 4.0.0, >= 4.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -55,5 +55,5 @@ DEPENDENCIES
|
|
55
55
|
bundler (~> 1.7)
|
56
56
|
omni_api!
|
57
57
|
rake (~> 10.0)
|
58
|
-
rspec
|
59
|
-
rspec-its
|
58
|
+
rspec (~> 3.3, >= 3.3.0)
|
59
|
+
rspec-its (~> 1.2, >= 1.2)
|
data/OmniApi.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Cristi Badila', 'Alexandru Calinoiu']
|
10
10
|
spec.email = %w(badila.cristi@agilefreaks.com calinoiu.alexandru@agilefreaks.com)
|
11
11
|
spec.summary = %q{A gem used to make using OmniApi easier}
|
12
|
-
spec.description = %q{}
|
12
|
+
spec.description = %q{Use this gem in your ruby projects to leverage the Omni api, we use it our web page.}
|
13
13
|
spec.homepage = 'https://github.com/Agilefreaks/OmniApiGem'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'activeresource', '~> 4.0.0'
|
21
|
+
spec.add_runtime_dependency 'activeresource', '~> 4.0.0', '>= 4.0.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
-
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'rspec-its'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
|
26
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2', '>= 1.2'
|
27
27
|
end
|
@@ -4,15 +4,15 @@ module OmniApi
|
|
4
4
|
include Singleton
|
5
5
|
|
6
6
|
def self.ensure_user_exists(auth)
|
7
|
-
OmniApi::UserFactory.instance.ensure_user_exists(auth)
|
7
|
+
OmniApi::Factories::UserFactory.instance.ensure_user_exists(auth)
|
8
8
|
end
|
9
9
|
|
10
10
|
def ensure_user_exists(auth)
|
11
|
-
api_user = OmniApi::User.where(email: auth.info.email).first
|
12
|
-
api_user || OmniApi::User.create(first_name: auth.info.first_name,
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
api_user = OmniApi::Resources::User.where(email: auth.info.email).first
|
12
|
+
api_user || OmniApi::Resources::User.create(first_name: auth.info.first_name,
|
13
|
+
last_name: auth.info.last_name,
|
14
|
+
email: auth.info.email.downcase,
|
15
|
+
image_url: auth.info.image)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -12,10 +12,10 @@ module OmniApi
|
|
12
12
|
|
13
13
|
def self.create_for(user_email)
|
14
14
|
instance = self.new
|
15
|
-
instance.attributes[:grant_type] = OmniApi::Oauth2::GrantTypes::CLIENT_CREDENTIALS
|
15
|
+
instance.attributes[:grant_type] = OmniApi::Resources::Oauth2::GrantTypes::CLIENT_CREDENTIALS
|
16
16
|
instance.attributes[:client_id] = OmniApi.config.client_id
|
17
17
|
instance.attributes[:client_secret] = OmniApi.config.client_secret
|
18
|
-
instance.attributes[:resource_type] = OmniApi::Oauth2::ResourceTypes::USER
|
18
|
+
instance.attributes[:resource_type] = OmniApi::Resources::Oauth2::ResourceTypes::USER
|
19
19
|
instance.attributes[:resource_id] = user_email
|
20
20
|
instance.save
|
21
21
|
instance
|
@@ -23,7 +23,7 @@ module OmniApi
|
|
23
23
|
|
24
24
|
def self.refresh(refresh_token)
|
25
25
|
instance = self.new
|
26
|
-
instance.attributes[:grant_type] = OmniApi::Oauth2::GrantTypes::REFRESH_TOKEN
|
26
|
+
instance.attributes[:grant_type] = OmniApi::Resources::Oauth2::GrantTypes::REFRESH_TOKEN
|
27
27
|
instance.attributes[:refresh_token] = refresh_token
|
28
28
|
instance.save
|
29
29
|
instance
|
@@ -8,7 +8,7 @@ module OmniApi
|
|
8
8
|
attr_accessible :phone_number, :content, :type, :state, :send_at
|
9
9
|
|
10
10
|
def self.schedule(options)
|
11
|
-
sms_message = OmniApi::SmsMessage.new(options)
|
11
|
+
sms_message = OmniApi::Resources::SmsMessage.new(options)
|
12
12
|
sms_message.state = :scheduled
|
13
13
|
sms_message.type = :outgoing
|
14
14
|
|
@@ -12,17 +12,6 @@ module OmniApi
|
|
12
12
|
new_headers['Authorization'] = OmniApi.config.user_access_token
|
13
13
|
new_headers
|
14
14
|
end
|
15
|
-
|
16
|
-
def self.connection(refresh = false)
|
17
|
-
@connection = create_new_connection if refresh || @connection.nil?
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
def self.create_new_connection
|
24
|
-
OmniApiConnection.new(site, format)
|
25
|
-
end
|
26
15
|
end
|
27
16
|
end
|
28
17
|
end
|
data/lib/omni_api/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniApi::Factories::UserFactory do
|
4
|
+
describe '.ensure_user_exists' do
|
5
|
+
let(:user_info) { double('info', email: 'test@email.com', first_name: 'first', last_name: 'last', image: 'test')}
|
6
|
+
let(:auth) { double('auth', info: user_info) }
|
7
|
+
|
8
|
+
subject { OmniApi::Factories::UserFactory.ensure_user_exists(auth) }
|
9
|
+
|
10
|
+
context 'a user with the given email exists' do
|
11
|
+
let(:user) { OmniApi::Resources::User.new({email: 'test@email.com', first_name: 'first', last_name: 'last', image_url: 'test'}) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
path = "/api/v1/users.json?email=#{ERB::Util.url_encode(user_info.email)}"
|
15
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
16
|
+
mock.get path, {'Accept' => 'application/json', 'Authorization' => 'bearer random'}, [user].to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it { is_expected.to eq user }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'a user with the given email does not exist' do
|
24
|
+
before do
|
25
|
+
path = "/api/v1/users.json?email=#{ERB::Util.url_encode(user_info.email)}"
|
26
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
27
|
+
mock.get path, {'Accept' => 'application/json', 'Authorization' => 'bearer random'}, [].to_json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'tries to create a user with the given info' do
|
32
|
+
expected_data = {email: 'test@email.com', first_name: 'first', last_name: 'last', image_url: 'test'}
|
33
|
+
expect(OmniApi::Resources::User).to receive(:create).with(expected_data)
|
34
|
+
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniApi::Resources::SmsMessage do
|
4
|
+
describe '.schedule' do
|
5
|
+
let(:message_details) { {phone_number: '1236', content: 'testC', send_at: DateTime.now } }
|
6
|
+
subject { OmniApi::Resources::SmsMessage.schedule(message_details) }
|
7
|
+
|
8
|
+
it { is_expected.to be_a(OmniApi::Resources::SmsMessage) }
|
9
|
+
its(:state) { is_expected.to be :scheduled }
|
10
|
+
its(:type) { is_expected.to be :outgoing }
|
11
|
+
its(:phone_number) { is_expected.to eq '1236' }
|
12
|
+
its(:content) { is_expected.to eq 'testC' }
|
13
|
+
its(:send_at) { is_expected.to eq message_details[:send_at] }
|
14
|
+
end
|
15
|
+
end
|
@@ -2,12 +2,6 @@ require 'spec_helper'
|
|
2
2
|
require 'uri'
|
3
3
|
|
4
4
|
describe OmniApi::Resources::User::UserResource do
|
5
|
-
describe '.connection' do
|
6
|
-
subject { OmniApi::Resources::User::UserResource.connection }
|
7
|
-
|
8
|
-
it { is_expected.to be_a(OmniApi::Resources::OmniApiConnection) }
|
9
|
-
end
|
10
|
-
|
11
5
|
describe '.site' do
|
12
6
|
subject { OmniApi::Resources::User::UserResource.site }
|
13
7
|
|
@@ -16,10 +16,4 @@ describe OmniApi::Resources::UserAuthorizedResource do
|
|
16
16
|
its(['Authorization']) { is_expected.to eq('bearer ') }
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
describe '.connection' do
|
21
|
-
subject { OmniApi::Resources::UserAuthorizedResource.connection }
|
22
|
-
|
23
|
-
it { is_expected.to be_a(OmniApi::Resources::OmniApiConnection) }
|
24
|
-
end
|
25
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@ require 'bundler/setup'
|
|
2
2
|
Bundler.setup
|
3
3
|
|
4
4
|
require 'rspec/its'
|
5
|
-
require '
|
5
|
+
require 'active_resource'
|
6
|
+
require 'active_support/json'
|
7
|
+
require 'omni_api'
|
6
8
|
OmniApi.config.base_url = 'http://localhost:9292/api/v1'
|
7
9
|
OmniApi.config.client_access_token = 'random'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omni_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
|
- Cristi Badila
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-09-
|
12
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
@@ -18,6 +18,9 @@ dependencies:
|
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 4.0.0
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 4.0.0
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -25,6 +28,9 @@ dependencies:
|
|
25
28
|
- - "~>"
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: 4.0.0
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: bundler
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,31 +63,44 @@ dependencies:
|
|
57
63
|
name: rspec
|
58
64
|
requirement: !ruby/object:Gem::Requirement
|
59
65
|
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
60
69
|
- - ">="
|
61
70
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
71
|
+
version: 3.3.0
|
63
72
|
type: :development
|
64
73
|
prerelease: false
|
65
74
|
version_requirements: !ruby/object:Gem::Requirement
|
66
75
|
requirements:
|
76
|
+
- - "~>"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '3.3'
|
67
79
|
- - ">="
|
68
80
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
81
|
+
version: 3.3.0
|
70
82
|
- !ruby/object:Gem::Dependency
|
71
83
|
name: rspec-its
|
72
84
|
requirement: !ruby/object:Gem::Requirement
|
73
85
|
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.2'
|
74
89
|
- - ">="
|
75
90
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
91
|
+
version: '1.2'
|
77
92
|
type: :development
|
78
93
|
prerelease: false
|
79
94
|
version_requirements: !ruby/object:Gem::Requirement
|
80
95
|
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '1.2'
|
81
99
|
- - ">="
|
82
100
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
84
|
-
description:
|
101
|
+
version: '1.2'
|
102
|
+
description: Use this gem in your ruby projects to leverage the Omni api, we use it
|
103
|
+
our web page.
|
85
104
|
email:
|
86
105
|
- badila.cristi@agilefreaks.com
|
87
106
|
- calinoiu.alexandru@agilefreaks.com
|
@@ -97,7 +116,6 @@ files:
|
|
97
116
|
- OmniApi.gemspec
|
98
117
|
- README.md
|
99
118
|
- Rakefile
|
100
|
-
- lib/OmniApi.rb
|
101
119
|
- lib/omni_api.rb
|
102
120
|
- lib/omni_api/concerns.rb
|
103
121
|
- lib/omni_api/concerns/.keep
|
@@ -124,8 +142,10 @@ files:
|
|
124
142
|
- lib/omni_api/resources/user/user_resource.rb
|
125
143
|
- lib/omni_api/resources/user_authorized_resource.rb
|
126
144
|
- lib/omni_api/version.rb
|
145
|
+
- spec/OmniApi/factories/user_factory_spec.rb
|
127
146
|
- spec/OmniApi/resources/client_spec.rb
|
128
147
|
- spec/OmniApi/resources/oauth2/token_spec.rb
|
148
|
+
- spec/OmniApi/resources/sms_message_spec.rb
|
129
149
|
- spec/OmniApi/resources/user/user_resource_spec.rb
|
130
150
|
- spec/OmniApi/resources/user_authorized_resource_spec.rb
|
131
151
|
- spec/OmniApi/resources/user_spec.rb
|
@@ -156,8 +176,10 @@ signing_key:
|
|
156
176
|
specification_version: 4
|
157
177
|
summary: A gem used to make using OmniApi easier
|
158
178
|
test_files:
|
179
|
+
- spec/OmniApi/factories/user_factory_spec.rb
|
159
180
|
- spec/OmniApi/resources/client_spec.rb
|
160
181
|
- spec/OmniApi/resources/oauth2/token_spec.rb
|
182
|
+
- spec/OmniApi/resources/sms_message_spec.rb
|
161
183
|
- spec/OmniApi/resources/user/user_resource_spec.rb
|
162
184
|
- spec/OmniApi/resources/user_authorized_resource_spec.rb
|
163
185
|
- spec/OmniApi/resources/user_spec.rb
|
data/lib/OmniApi.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'omni_api'
|