omni_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.versions.conf +4 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +59 -0
  6. data/LICENSE.txt +22 -0
  7. data/OmniApi.gemspec +27 -0
  8. data/README.md +31 -0
  9. data/Rakefile +2 -0
  10. data/lib/OmniApi.rb +1 -0
  11. data/lib/omni_api.rb +13 -0
  12. data/lib/omni_api/concerns.rb +6 -0
  13. data/lib/omni_api/concerns/.keep +0 -0
  14. data/lib/omni_api/concerns/attributes.rb +16 -0
  15. data/lib/omni_api/concerns/timestamps.rb +11 -0
  16. data/lib/omni_api/config.rb +37 -0
  17. data/lib/omni_api/factories.rb +6 -0
  18. data/lib/omni_api/factories/user_factory.rb +19 -0
  19. data/lib/omni_api/resources.rb +8 -0
  20. data/lib/omni_api/resources/authorization_code.rb +11 -0
  21. data/lib/omni_api/resources/base_client_model.rb +11 -0
  22. data/lib/omni_api/resources/base_model.rb +13 -0
  23. data/lib/omni_api/resources/client.rb +13 -0
  24. data/lib/omni_api/resources/oauth2/grant_types.rb +11 -0
  25. data/lib/omni_api/resources/oauth2/resource_types.rb +10 -0
  26. data/lib/omni_api/resources/oauth2/token.rb +38 -0
  27. data/lib/omni_api/resources/omni_api_connection.rb +21 -0
  28. data/lib/omni_api/resources/payment_plan.rb +8 -0
  29. data/lib/omni_api/resources/phone_call.rb +11 -0
  30. data/lib/omni_api/resources/sms_message.rb +19 -0
  31. data/lib/omni_api/resources/user.rb +15 -0
  32. data/lib/omni_api/resources/user/client_association.rb +13 -0
  33. data/lib/omni_api/resources/user/device.rb +13 -0
  34. data/lib/omni_api/resources/user/user_resource.rb +11 -0
  35. data/lib/omni_api/resources/user_authorized_resource.rb +28 -0
  36. data/lib/omni_api/version.rb +3 -0
  37. data/spec/OmniApi/resources/client_spec.rb +11 -0
  38. data/spec/OmniApi/resources/oauth2/token_spec.rb +9 -0
  39. data/spec/OmniApi/resources/user/user_resource_spec.rb +16 -0
  40. data/spec/OmniApi/resources/user_authorized_resource_spec.rb +25 -0
  41. data/spec/OmniApi/resources/user_spec.rb +40 -0
  42. data/spec/OmniApi_spec.rb +10 -0
  43. data/spec/spec_helper.rb +7 -0
  44. metadata +165 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d273c8fa810ea80870a321152d1d4c368208f1d6
4
+ data.tar.gz: 2bd813e3b7bd864ec186372095661ebde2ee4c10
5
+ SHA512:
6
+ metadata.gz: 78800b549b460bb80abed2248b70e73ab2074abbee7ea6273edc06ddc4ac5a428a059572ab25333b7cdce41f5d96098a7c22b8cfb24ed8ec660d1e0767cd71a5
7
+ data.tar.gz: 11e6f61d2b448e867d9b4ada1e138ab370f86e87ea8a9ca02b1bcb2fa7d91001e4447e305da564a7ac37dc275c48cd9ba417888e10723e28b1b12b99fc4ddc5e
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+ /.project
data/.versions.conf ADDED
@@ -0,0 +1,4 @@
1
+ ruby=ruby-2.2.1
2
+ ruby-gemset=omniapi-gem
3
+ #ruby-gem-install=bundler rake
4
+ #ruby-bundle-install=true
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in OmniApi.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omni_api (0.0.1)
5
+ activeresource (~> 4.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (4.2.4)
11
+ activesupport (= 4.2.4)
12
+ builder (~> 3.1)
13
+ activeresource (4.0.0)
14
+ activemodel (~> 4.0)
15
+ activesupport (~> 4.0)
16
+ rails-observers (~> 0.1.1)
17
+ activesupport (4.2.4)
18
+ i18n (~> 0.7)
19
+ json (~> 1.7, >= 1.7.7)
20
+ minitest (~> 5.1)
21
+ thread_safe (~> 0.3, >= 0.3.4)
22
+ tzinfo (~> 1.1)
23
+ builder (3.2.2)
24
+ diff-lcs (1.2.5)
25
+ i18n (0.7.0)
26
+ json (1.8.3)
27
+ minitest (5.8.0)
28
+ rails-observers (0.1.2)
29
+ activemodel (~> 4.0)
30
+ rake (10.4.2)
31
+ rspec (3.3.0)
32
+ rspec-core (~> 3.3.0)
33
+ rspec-expectations (~> 3.3.0)
34
+ rspec-mocks (~> 3.3.0)
35
+ rspec-core (3.3.2)
36
+ rspec-support (~> 3.3.0)
37
+ rspec-expectations (3.3.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.3.0)
40
+ rspec-its (1.2.0)
41
+ rspec-core (>= 3.0.0)
42
+ rspec-expectations (>= 3.0.0)
43
+ rspec-mocks (3.3.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.3.0)
46
+ rspec-support (3.3.0)
47
+ thread_safe (0.3.5)
48
+ tzinfo (1.2.2)
49
+ thread_safe (~> 0.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 1.7)
56
+ omni_api!
57
+ rake (~> 10.0)
58
+ rspec
59
+ rspec-its
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Cristi Badila
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/OmniApi.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omni_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'omni_api'
8
+ spec.version = OmniApi::VERSION
9
+ spec.authors = ['Cristi Badila', 'Alexandru Calinoiu']
10
+ spec.email = %w(badila.cristi@agilefreaks.com calinoiu.alexandru@agilefreaks.com)
11
+ spec.summary = %q{A gem used to make using OmniApi easier}
12
+ spec.description = %q{}
13
+ spec.homepage = 'https://github.com/Agilefreaks/OmniApiGem'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'activeresource', '~> 4.0.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'rspec-its'
27
+ end
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # OmniApi
2
+
3
+ A gem which makes using the OmniAPI easier
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'OmniApi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install OmniApi
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/cristibadila/OmniApi/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/OmniApi.rb ADDED
@@ -0,0 +1 @@
1
+ require 'omni_api'
data/lib/omni_api.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'singleton'
2
+ require 'active_support'
3
+
4
+ require 'omni_api/version'
5
+ require 'omni_api/config'
6
+
7
+ module OmniApi
8
+ extend ActiveSupport::Autoload
9
+
10
+ autoload :Factories
11
+ autoload :Concerns
12
+ autoload :Resources
13
+ end
@@ -0,0 +1,6 @@
1
+ module OmniApi
2
+ module Concerns
3
+ root_dir = File.expand_path('../concerns', __FILE__)
4
+ Dir.glob(File.join(root_dir, '**', '*.rb')).each { |f| require(f) }
5
+ end
6
+ end
File without changes
@@ -0,0 +1,16 @@
1
+ module OmniApi
2
+ module Concerns
3
+ module Attributes
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def attr_accessible(*attr)
8
+ attr.each do |a|
9
+ define_method(a) { attributes[a] }
10
+ define_method("#{a}=") { |val| attributes[a] = val }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module OmniApi
2
+ module Concerns
3
+ module Timestamps
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ attr_accessible :updated_at, :created_at
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ module OmniApi
2
+ mattr_accessor :test_mode
3
+ self.test_mode = false
4
+
5
+ mattr_accessor :client_access_token
6
+ self.client_access_token = ''
7
+
8
+ mattr_accessor :client_id
9
+ self.client_id = ''
10
+
11
+ mattr_accessor :client_secret
12
+ self.client_secret = ''
13
+
14
+ # rubocop:disable Style/ClassVars
15
+ def self.client_access_token=(token)
16
+ @@client_access_token = "bearer #{token}"
17
+ end
18
+
19
+ mattr_accessor :user_access_token
20
+ self.user_access_token = ''
21
+
22
+ # rubocop:disable Style/ClassVars
23
+ def self.user_access_token=(token)
24
+ @@user_access_token = "bearer #{token}"
25
+ end
26
+
27
+ mattr_accessor :base_url
28
+ self.base_url = ''
29
+
30
+ def self.config
31
+ self
32
+ end
33
+
34
+ def self.setup
35
+ yield self
36
+ end
37
+ end
@@ -0,0 +1,6 @@
1
+ module OmniApi
2
+ module Factories
3
+ root_dir = File.expand_path('../factories', __FILE__)
4
+ Dir.glob(File.join(root_dir, '**', '*.rb')).each { |f| require(f) }
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ module OmniApi
2
+ module Factories
3
+ class UserFactory
4
+ include Singleton
5
+
6
+ def self.ensure_user_exists(auth)
7
+ OmniApi::UserFactory.instance.ensure_user_exists(auth)
8
+ end
9
+
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
+ last_name: auth.info.last_name,
14
+ email: auth.info.email.downcase,
15
+ image_url: auth.info.image)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require 'active_resource'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ root_dir = File.expand_path('../resources', __FILE__)
6
+ Dir.glob(File.join(root_dir, '**', '*.rb')).each { |f| require(f) }
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'base_client_model'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class AuthorizationCode < BaseClientModel
6
+ include OmniApi::Concerns::Timestamps
7
+
8
+ attr_accessible :id, :code
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'base_model'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class BaseClientModel < BaseModel
6
+ self.site = OmniApi.config.base_url
7
+
8
+ headers['Authorization'] = OmniApi.config.client_access_token
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_resource/base'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class BaseModel < ActiveResource::Base
6
+ include Concerns::Attributes
7
+
8
+ def as_json(_options = nil)
9
+ attributes
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'base_client_model'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class Client < BaseClientModel
6
+ attr_accessible :id, :name, :scopes
7
+
8
+ def locale
9
+ 'ro'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module OmniApi
2
+ module Resources
3
+ module Oauth2
4
+ module GrantTypes
5
+ AUTHORIZATION_CODE = 'authorization_code'
6
+ REFRESH_TOKEN = 'refresh_token'
7
+ CLIENT_CREDENTIALS = 'client_credentials'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module OmniApi
2
+ module Resources
3
+ module Oauth2
4
+ module ResourceTypes
5
+ USER = 'user'
6
+ CLIENT = 'client'
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../base_client_model'
2
+ require_relative 'grant_types'
3
+ require_relative 'resource_types'
4
+
5
+ module OmniApi
6
+ module Resources
7
+ module Oauth2
8
+ class Token < OmniApi::Resources::BaseClientModel
9
+ attr_accessible :access_token, :refresh_token, :token_type, :expires_in
10
+
11
+ self.site = "#{OmniApi.config.base_url}/oauth2"
12
+
13
+ def self.create_for(user_email)
14
+ instance = self.new
15
+ instance.attributes[:grant_type] = OmniApi::Oauth2::GrantTypes::CLIENT_CREDENTIALS
16
+ instance.attributes[:client_id] = OmniApi.config.client_id
17
+ instance.attributes[:client_secret] = OmniApi.config.client_secret
18
+ instance.attributes[:resource_type] = OmniApi::Oauth2::ResourceTypes::USER
19
+ instance.attributes[:resource_id] = user_email
20
+ instance.save
21
+ instance
22
+ end
23
+
24
+ def self.refresh(refresh_token)
25
+ instance = self.new
26
+ instance.attributes[:grant_type] = OmniApi::Oauth2::GrantTypes::REFRESH_TOKEN
27
+ instance.attributes[:refresh_token] = refresh_token
28
+ instance.save
29
+ instance
30
+ end
31
+
32
+ def self.collection_name
33
+ 'token'
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_resource/connection'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class OmniApiConnection < ActiveResource::Connection
6
+ def initialize(site, format = ActiveResource::Formats::JsonFormat)
7
+ super
8
+ end
9
+
10
+ attr_accessor :error_handler
11
+
12
+ private
13
+
14
+ def request(method, path, *arguments)
15
+ super
16
+ rescue Error => e
17
+ error_handler.present? ? error_handler.handle(e) : raise
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ module OmniApi
2
+ module Resources
3
+ module PaymentPlan
4
+ FREE = 'free'
5
+ PREMIUM = 'premium'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'user_authorized_resource'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class PhoneCall < UserAuthorizedResource
6
+ include OmniApi::Concerns::Timestamps
7
+
8
+ attr_accessible :id, :number, :type, :state
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'base_client_model'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class SmsMessage < BaseClientModel
6
+ include OmniApi::Concerns::Timestamps
7
+
8
+ attr_accessible :phone_number, :content, :type, :state, :send_at
9
+
10
+ def self.schedule(options)
11
+ sms_message = OmniApi::SmsMessage.new(options)
12
+ sms_message.state = :scheduled
13
+ sms_message.type = :outgoing
14
+
15
+ sms_message
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'base_client_model'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class User < BaseClientModel
6
+ include OmniApi::Concerns::Timestamps
7
+
8
+ attr_accessible :first_name, :last_name, :plan
9
+
10
+ def self.change_plan!(email, plan)
11
+ put plan.to_s, [], {email: email}.to_json
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'user_resource'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class User
6
+ class ClientAssociation < UserResource
7
+ include OmniApi::Concerns::Timestamps
8
+
9
+ attr_accessible :id, :client_url, :client_name, :token, :refresh_token, :client_id
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'user_resource'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class User
6
+ class Device < UserResource
7
+ include OmniApi::Concerns::Timestamps
8
+
9
+ attr_accessible :id, :name, :registration_id
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../user_authorized_resource'
2
+
3
+ module OmniApi
4
+ module Resources
5
+ class User
6
+ class UserResource < UserAuthorizedResource
7
+ self.site = "#{OmniApi.config.base_url}/user"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'base_client_model'
2
+ require_relative 'user'
3
+
4
+ module OmniApi
5
+ module Resources
6
+ class UserAuthorizedResource < BaseClientModel
7
+ cattr_accessor :static_headers
8
+ self.static_headers = headers
9
+
10
+ def self.headers
11
+ new_headers = static_headers.clone
12
+ new_headers['Authorization'] = OmniApi.config.user_access_token
13
+ new_headers
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
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module OmniApi
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniApi::Resources::Client do
4
+ let(:instance ) { OmniApi::Resources::Client.new }
5
+
6
+ describe :locale do
7
+ subject { instance.locale }
8
+
9
+ it { is_expected.to eq('ro') }
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniApi::Resources::Oauth2::Token do
4
+ describe '.collection_name' do
5
+ subject { OmniApi::Resources::Oauth2::Token.collection_name }
6
+
7
+ it { is_expected.to eq('token') }
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+
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
+ describe '.site' do
12
+ subject { OmniApi::Resources::User::UserResource.site }
13
+
14
+ it { is_expected.to eq URI.parse("#{OmniApi.config.base_url}/user") }
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniApi::Resources::UserAuthorizedResource do
4
+ describe '.headers' do
5
+ subject { OmniApi::Resources::UserAuthorizedResource.headers }
6
+
7
+ context 'the OmniApi config contains a user access token' do
8
+ before { OmniApi.config.user_access_token = 'someToken' }
9
+
10
+ its(['Authorization']) { is_expected.to eq('bearer someToken') }
11
+ end
12
+
13
+ context 'the OmniApi config does not contain a user access token' do
14
+ before { OmniApi.config.user_access_token = nil }
15
+
16
+ its(['Authorization']) { is_expected.to eq('bearer ') }
17
+ end
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
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniApi::Resources::User do
4
+ it { should respond_to :first_name }
5
+ it { should respond_to :last_name }
6
+
7
+ describe :element_path do
8
+ subject { OmniApi::Resources::User.element_path('1') }
9
+
10
+ it { should == '/api/v1/users/1.json' }
11
+ end
12
+
13
+ describe :change_plan! do
14
+ let(:plan) { '' }
15
+ subject { OmniApi::Resources::User.change_plan!('email@domain.com', plan) }
16
+
17
+ context 'to premium' do
18
+ let(:plan) { OmniApi::Resources::PaymentPlan::PREMIUM }
19
+
20
+ before do
21
+ ActiveResource::HttpMock.respond_to do |mock|
22
+ mock.put '/api/v1/users/premium.json', {'Content-Type' => 'application/json', 'Authorization' => 'bearer random'}, 'email' => 'email@domain.com'
23
+ end
24
+ end
25
+
26
+ it('makes the api call to make the user a premium user') { should.nil? }
27
+ end
28
+
29
+ context 'to_basic' do
30
+ let(:plan) { :basic }
31
+ before do
32
+ ActiveResource::HttpMock.respond_to do |mock|
33
+ mock.put '/api/v1/users/basic.json', {'Content-Type' => 'application/json', 'Authorization' => 'bearer random'}, 'email' => 'email@domain.com'
34
+ end
35
+ end
36
+
37
+ it('makes the api call to make the user a basic user') { should.nil? }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniApi do
4
+ describe 'configuration' do
5
+ it 'will prefix access token with bearer' do
6
+ OmniApi.config.client_access_token = 'token'
7
+ expect(OmniApi.config.client_access_token).to eq('bearer token')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'rspec/its'
5
+ require 'OmniApi'
6
+ OmniApi.config.base_url = 'http://localhost:9292/api/v1'
7
+ OmniApi.config.client_access_token = 'random'
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omni_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cristi Badila
8
+ - Alexandru Calinoiu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-09-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activeresource
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 4.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 4.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.7'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.7'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec-its
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: ''
85
+ email:
86
+ - badila.cristi@agilefreaks.com
87
+ - calinoiu.alexandru@agilefreaks.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".versions.conf"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - OmniApi.gemspec
98
+ - README.md
99
+ - Rakefile
100
+ - lib/OmniApi.rb
101
+ - lib/omni_api.rb
102
+ - lib/omni_api/concerns.rb
103
+ - lib/omni_api/concerns/.keep
104
+ - lib/omni_api/concerns/attributes.rb
105
+ - lib/omni_api/concerns/timestamps.rb
106
+ - lib/omni_api/config.rb
107
+ - lib/omni_api/factories.rb
108
+ - lib/omni_api/factories/user_factory.rb
109
+ - lib/omni_api/resources.rb
110
+ - lib/omni_api/resources/authorization_code.rb
111
+ - lib/omni_api/resources/base_client_model.rb
112
+ - lib/omni_api/resources/base_model.rb
113
+ - lib/omni_api/resources/client.rb
114
+ - lib/omni_api/resources/oauth2/grant_types.rb
115
+ - lib/omni_api/resources/oauth2/resource_types.rb
116
+ - lib/omni_api/resources/oauth2/token.rb
117
+ - lib/omni_api/resources/omni_api_connection.rb
118
+ - lib/omni_api/resources/payment_plan.rb
119
+ - lib/omni_api/resources/phone_call.rb
120
+ - lib/omni_api/resources/sms_message.rb
121
+ - lib/omni_api/resources/user.rb
122
+ - lib/omni_api/resources/user/client_association.rb
123
+ - lib/omni_api/resources/user/device.rb
124
+ - lib/omni_api/resources/user/user_resource.rb
125
+ - lib/omni_api/resources/user_authorized_resource.rb
126
+ - lib/omni_api/version.rb
127
+ - spec/OmniApi/resources/client_spec.rb
128
+ - spec/OmniApi/resources/oauth2/token_spec.rb
129
+ - spec/OmniApi/resources/user/user_resource_spec.rb
130
+ - spec/OmniApi/resources/user_authorized_resource_spec.rb
131
+ - spec/OmniApi/resources/user_spec.rb
132
+ - spec/OmniApi_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: https://github.com/Agilefreaks/OmniApiGem
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.6
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A gem used to make using OmniApi easier
158
+ test_files:
159
+ - spec/OmniApi/resources/client_spec.rb
160
+ - spec/OmniApi/resources/oauth2/token_spec.rb
161
+ - spec/OmniApi/resources/user/user_resource_spec.rb
162
+ - spec/OmniApi/resources/user_authorized_resource_spec.rb
163
+ - spec/OmniApi/resources/user_spec.rb
164
+ - spec/OmniApi_spec.rb
165
+ - spec/spec_helper.rb