oneaccess 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +21 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +105 -0
  7. data/README.md +105 -0
  8. data/Rakefile +10 -0
  9. data/circle.yml +9 -0
  10. data/console +1 -0
  11. data/lib/oneaccess/api/base.rb +57 -0
  12. data/lib/oneaccess/api/entitlement/organization/product_group.rb +24 -0
  13. data/lib/oneaccess/api/entitlement/user/product_group.rb +24 -0
  14. data/lib/oneaccess/api/research.rb +21 -0
  15. data/lib/oneaccess/api/user.rb +15 -0
  16. data/lib/oneaccess/configuration.rb +14 -0
  17. data/lib/oneaccess/data_object/address.rb +16 -0
  18. data/lib/oneaccess/data_object/city.rb +17 -0
  19. data/lib/oneaccess/data_object/country.rb +16 -0
  20. data/lib/oneaccess/data_object/global_region.rb +16 -0
  21. data/lib/oneaccess/data_object/organization_light.rb +11 -0
  22. data/lib/oneaccess/data_object/product_group.rb +43 -0
  23. data/lib/oneaccess/data_object/region.rb +12 -0
  24. data/lib/oneaccess/data_object/representer/address.rb +20 -0
  25. data/lib/oneaccess/data_object/representer/city.rb +22 -0
  26. data/lib/oneaccess/data_object/representer/country.rb +23 -0
  27. data/lib/oneaccess/data_object/representer/global_region.rb +26 -0
  28. data/lib/oneaccess/data_object/representer/organization_light.rb +13 -0
  29. data/lib/oneaccess/data_object/representer/product_group.rb +18 -0
  30. data/lib/oneaccess/data_object/representer/region.rb +15 -0
  31. data/lib/oneaccess/data_object/representer/research_document_info.rb +17 -0
  32. data/lib/oneaccess/data_object/representer/saml_info.rb +14 -0
  33. data/lib/oneaccess/data_object/representer/user.rb +25 -0
  34. data/lib/oneaccess/data_object/research_document_info.rb +12 -0
  35. data/lib/oneaccess/data_object/saml_info.rb +14 -0
  36. data/lib/oneaccess/data_object/user.rb +20 -0
  37. data/lib/oneaccess/enum/api_status_code.rb +12 -0
  38. data/lib/oneaccess/enum/product_group_status.rb +7 -0
  39. data/lib/oneaccess/enum/product_type.rb +9 -0
  40. data/lib/oneaccess/error/api_error.rb +17 -0
  41. data/lib/oneaccess/response/api_error.rb +11 -0
  42. data/lib/oneaccess/response/product_groups_response.rb +20 -0
  43. data/lib/oneaccess/response/representer/api_error.rb +13 -0
  44. data/lib/oneaccess/response/representer/product_groups_response.rb +20 -0
  45. data/lib/oneaccess/response/representer/research_document_response.rb +17 -0
  46. data/lib/oneaccess/response/representer/user_response.rb +15 -0
  47. data/lib/oneaccess/response/research_document_response.rb +15 -0
  48. data/lib/oneaccess/response/user_response.rb +15 -0
  49. data/lib/oneaccess/serializable.rb +14 -0
  50. data/lib/oneaccess.rb +22 -0
  51. data/oneaccess.gemspec +29 -0
  52. data/release +9 -0
  53. metadata +55 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cae42a24d0cf2773ecb31820ad2eeae1efbf383c
4
- data.tar.gz: 244900a83db61df3a04873f4f54170633f292631
3
+ metadata.gz: 30dd9ac3513fca2659dc828b8c4a85d2f54aa629
4
+ data.tar.gz: ab06c8eb41a0e7de85f8821fbe152d40ba96633a
5
5
  SHA512:
6
- metadata.gz: ef2dc321b38d61f87fe4ac586b9916239a720c828afb6a3bf6f49db55118ba88e1f666c2fd03113dc9ed388669f88151f8aecd17b67497feb579343613783f53
7
- data.tar.gz: fe7df37936bfe7e51c969d54f4f0fd10af29cc7f0cae08a3ddcc94bdd92d825a1e23263fe179d855e202a186d00e21ee670b11e90e9c1a07f16e752243006ba8
6
+ metadata.gz: ea9db92248596b40291813288865189fa8a500f9febcbc1fde81d301c77981d1d7066d8ed7078bd0da5f6818c768df177dca292fd19a6d1885c5a8e3f44c6af7
7
+ data.tar.gz: 237723faf8bafff4e210b7d2a01f1e1f13f4c20310db148b954e574ca1734263d22cda2e1375ebd91f6c07c2cfbbca895b2342a40167488d1092899d86feb63c
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .byebug_history
2
+ *.gem
3
+ *.bak
4
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+ Style/StringLiterals:
4
+ EnforcedStyle: double_quotes
5
+ Style/AlignHash:
6
+ EnforcedHashRocketStyle: table
7
+ EnforcedColonStyle: table
8
+ Metrics/ClassLength:
9
+ Max: 120
10
+ Metrics/LineLength:
11
+ Max: 120
12
+ Metrics/AbcSize:
13
+ Max: 18
14
+ AllCops:
15
+ TargetRubyVersion: 2.3
16
+ DisplayCopNames: true
17
+ DisplayStyleGuide: true
18
+ Exclude:
19
+ - 'spec/**/*'
20
+ - 'test/**/*'
21
+ - 'vendor/**/*'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,105 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ oneaccess (0.0.0)
5
+ multi_json (~> 1.12.0)
6
+ representable (~> 3.0.4)
7
+ rest-client (~> 2.0.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.5.1)
13
+ public_suffix (~> 2.0, >= 2.0.2)
14
+ ansi (1.5.0)
15
+ ast (2.3.0)
16
+ byebug (9.1.0)
17
+ crack (0.4.3)
18
+ safe_yaml (~> 1.0.0)
19
+ declarative (0.0.10)
20
+ declarative-option (0.1.0)
21
+ diff-lcs (1.3)
22
+ docile (1.1.5)
23
+ domain_name (0.5.20170404)
24
+ unf (>= 0.0.5, < 1.0.0)
25
+ hashdiff (0.3.5)
26
+ hirb (0.7.3)
27
+ http-cookie (1.0.3)
28
+ domain_name (~> 0.5)
29
+ json (2.1.0)
30
+ mime-types (3.1)
31
+ mime-types-data (~> 3.2015)
32
+ mime-types-data (3.2016.0521)
33
+ multi_json (1.12.1)
34
+ netrc (0.11.0)
35
+ parser (2.4.0.0)
36
+ ast (~> 2.2)
37
+ powerpack (0.1.1)
38
+ public_suffix (2.0.5)
39
+ rainbow (2.2.2)
40
+ rake
41
+ rake (11.3.0)
42
+ representable (3.0.4)
43
+ declarative (< 0.1.0)
44
+ declarative-option (< 0.2.0)
45
+ uber (< 0.2.0)
46
+ rest-client (2.0.2)
47
+ http-cookie (>= 1.0.2, < 2.0)
48
+ mime-types (>= 1.16, < 4.0)
49
+ netrc (~> 0.8)
50
+ rspec (3.7.0)
51
+ rspec-core (~> 3.7.0)
52
+ rspec-expectations (~> 3.7.0)
53
+ rspec-mocks (~> 3.7.0)
54
+ rspec-core (3.7.0)
55
+ rspec-support (~> 3.7.0)
56
+ rspec-expectations (3.7.0)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.7.0)
59
+ rspec-mocks (3.7.0)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.7.0)
62
+ rspec-support (3.7.0)
63
+ rubocop (0.45.0)
64
+ parser (>= 2.3.1.1, < 3.0)
65
+ powerpack (~> 0.1)
66
+ rainbow (>= 1.99.1, < 3.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (~> 1.0, >= 1.0.1)
69
+ ruby-progressbar (1.9.0)
70
+ safe_yaml (1.0.4)
71
+ simplecov (0.15.1)
72
+ docile (~> 1.1.0)
73
+ json (>= 1.8, < 3)
74
+ simplecov-html (~> 0.10.0)
75
+ simplecov-console (0.4.2)
76
+ ansi
77
+ hirb
78
+ simplecov
79
+ simplecov-html (0.10.2)
80
+ uber (0.1.0)
81
+ unf (0.1.4)
82
+ unf_ext
83
+ unf_ext (0.0.7.4)
84
+ unicode-display_width (1.3.0)
85
+ webmock (3.0.1)
86
+ addressable (>= 2.3.6)
87
+ crack (>= 0.3.2)
88
+ hashdiff
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ bundler (~> 1.12)
95
+ byebug
96
+ oneaccess!
97
+ rake (~> 11.3)
98
+ rspec (~> 3.6)
99
+ rubocop (~> 0.45.0)
100
+ simplecov
101
+ simplecov-console
102
+ webmock (~> 3.0.1)
103
+
104
+ BUNDLED WITH
105
+ 1.15.3
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # ONEAccess for Ruby
2
+ This is a ruby gem that wraps the ONEAccess API in an easy to use ruby library, so the API can be accesses transparently by invoking methods.
3
+
4
+ The full documentation about the ONEAccess API can be found at:
5
+ http://apidocs.oneaccess.io/docs
6
+
7
+ Currently, only the version `v1.1` is supported by this gem.
8
+
9
+ ## Installation & Setup
10
+ Install the gem directly:
11
+ ```
12
+ gem install oneaccess
13
+ ```
14
+
15
+ or add it to your `Gemfile`:
16
+ ```
17
+ gem 'oneaccess'
18
+ ```
19
+
20
+ The gem must be initialized with the API keys. If it's being used in a Rails project, then the file `/config/initializers/oneaccess.rb` should be created:
21
+ ```ruby
22
+ ONEAccess.configure do |config|
23
+ config.api_key = 'API_KEY_HERE'
24
+ config.master_api_key = 'MASTER_API_KEY_HERE'
25
+ end
26
+ ```
27
+
28
+ ## Tests
29
+ The tests are written in RSpec. Run the `rspec` in the root directory of the project.
30
+ A coverage report is automatically generated and stored under `/coverage`.
31
+
32
+ ## Documentation
33
+ The API and data model has been converted into ruby modules and classes following the same organization as defined in the OA documentation, but adapted to the ruby convetions (underscored instead of camelCase). Therefore, by reading the official documentation you can easily infer what the ruby API will look like.
34
+
35
+ Not all the methods in the API are currently supported, here's a list of all suported calls:
36
+
37
+ - User by Email: _/user/getByEmail_
38
+ - Research Document: _/research/document_
39
+ - Research Document by User ID: _/research/documentByUserId_
40
+ - Organization's Product Groups: _/entitlement/organization/productgroup/getList_
41
+ - User's Product Groups: _/entitlement/user/productgroup/getList_
42
+
43
+ ### User by Email _(/user/getByEmail)_
44
+ Official Documentation: http://apidocs.oneaccess.io/docs/usergetorcreate
45
+
46
+ This method returns a `User` object if it matches the first name, last name, and email. If there's not a match, then a new user is created and returned.
47
+
48
+ #### How to use:
49
+ ```ruby
50
+ resp = ONEAccess::API::User.getByEmail(first_name: 'Alex', last_name: 'Santos', email: 'alex@ae.com')
51
+
52
+ resp.data #=> instance of ONEAcess::DataObject::User
53
+ resp.data.id #=> 305 (id of the user)
54
+ resp.data.organization.id #=> 805 (id of the company)
55
+ resp.data.email #=> alex@ae.com
56
+ ```
57
+
58
+ ### Research Document _(/research/document)_
59
+ Official Documentation: http://apidocs.oneaccess.io/docs/researchdocument
60
+
61
+ This method retrieves a research document by providing the research ID and the first name, last name, and email of the user requesting access. If the user does not have access to the research, a `ONEAccess::Error:APIError` exception will be raisen.
62
+
63
+ #### How to use:
64
+ ```ruby
65
+ begin
66
+ resp = ONEAccess::API::Research.document(document_id: 2341, first_name: 'Alex', last_name: 'Santos', email: 'alex@ae.com')
67
+
68
+ resp.data #=> instance of ONEAcess::DataObject::ResearchDocumentInfo
69
+ resp.data.url #=> url of the document
70
+ resp.data.title #=> document's title
71
+ resp.data.saml #=> instance of ONEAccess::DataObject::SAMLInfo
72
+
73
+ puts "requires SAML" unless resp.data.saml.nil?
74
+
75
+ rescue ONEAccess::Error::APIError => e
76
+ if e.api_status_code == ONEAccess::APIStatusCode::OBJECT_NOT_FOUND
77
+ puts "Not entitled or does not exist"
78
+ end
79
+ end
80
+ ```
81
+
82
+ ### Research Document by User ID _(/research/documentByUserId)_
83
+ Official Documentation: http://apidocs.oneaccess.io/docs/researchdocumentbyuserid
84
+
85
+ Similar to the previous method, this method retrieves a research document by providing the research ID, but together with the user's ID instead. If the user does not have access to the research, a `ONEAccess::Error:APIError` exception will be raisen.
86
+
87
+ #### How to use:
88
+ ```ruby
89
+ begin
90
+ resp = ONEAccess::API::Research.document_by_user_id(document_id: 2341, user_id: 805)
91
+
92
+ resp.data #=> instance of ONEAcess::DataObject::ResearchDocumentInfo
93
+ resp.data.url #=> url of the document
94
+ resp.data.title #=> document's title
95
+ resp.data.saml #=> instance of ONEAccess::DataObject::SAMLInfo
96
+
97
+ puts "requires SAML" unless resp.data.saml.nil?
98
+
99
+ rescue ONEAccess::Error::APIError => e
100
+ if e.api_status_code == ONEAccess::APIStatusCode::OBJECT_NOT_FOUND
101
+ puts "Not entitled or does not exist"
102
+ end
103
+ end
104
+ ```
105
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ end
8
+ desc "Run tests"
9
+
10
+ task default: :test
data/circle.yml ADDED
@@ -0,0 +1,9 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.3
4
+ test:
5
+ override:
6
+ - bundle exec rake
7
+ - bundle exec rspec
8
+ post:
9
+ - bundle exec rubocop
data/console ADDED
@@ -0,0 +1 @@
1
+ irb -I . -r lib/oneaccess.rb
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+ require "rest-client"
3
+ require "json"
4
+ require_relative "../response/api_error"
5
+ require_relative "../error/api_error"
6
+
7
+ module ONEAccess
8
+ module API
9
+ class Base
10
+ class << self
11
+ def get(method, params = {})
12
+ RestClient.get(api_url(method), { params: params }.merge(auth_headers))
13
+ rescue RestClient::Exception => e
14
+ raise create_api_error(e)
15
+ end
16
+
17
+ def resource_api_path
18
+ const_get("RESOURCE_API_PATH")
19
+ rescue
20
+ nil
21
+ end
22
+
23
+ def api_url(method = nil)
24
+ url = "#{Configuration.base_url}#{resource_api_path}"
25
+ return url if method.nil?
26
+ "#{url}/#{method}"
27
+ end
28
+
29
+ protected
30
+
31
+ def api_path(path)
32
+ raise "API path has already been set" if resource_api_path
33
+ self.resource_api_path = path
34
+ end
35
+
36
+ private
37
+
38
+ def create_api_error(error)
39
+ api_error_data = Response::APIError.new
40
+ Response::Representer::APIError.new(api_error_data).from_json(error.http_body)
41
+ Error::APIError.new(error.http_code, api_error_data.api_status_code, api_error_data.api_status_message)
42
+ end
43
+
44
+ def resource_api_path=(path)
45
+ const_set("RESOURCE_API_PATH", path)
46
+ end
47
+
48
+ def auth_headers
49
+ {
50
+ "X-One-Access-Api-Key" => Configuration.api_key,
51
+ "Authorization" => "X-One-Access-Master-Api-Key #{Configuration.master_api_key}"
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../../../response/product_groups_response"
3
+
4
+ module ONEAccess
5
+ module API
6
+ module Entitlement
7
+ module Organization
8
+ class ProductGroup < Base
9
+ api_path "/entitlement/organization/productgroup"
10
+
11
+ def self.get_list(contributor_org_id:, page_number: 0, page_size: 20, type: nil)
12
+ resp = get("getList", Query: {
13
+ PageNumber: page_number,
14
+ PageSize: page_size,
15
+ ContributorOrgId: contributor_org_id,
16
+ Type: type
17
+ }.to_json)
18
+ Response::ProductGroupsResponse.from_json(resp.body)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../../../response/product_groups_response"
3
+
4
+ module ONEAccess
5
+ module API
6
+ module Entitlement
7
+ module User
8
+ class ProductGroup < Base
9
+ api_path "/entitlement/user/productgroup"
10
+
11
+ def self.get_list(user_id:, page_number: 0, page_size: 20, type: nil)
12
+ resp = get("getList", Query: {
13
+ PageNumber: page_number,
14
+ PageSize: page_size,
15
+ UserId: user_id,
16
+ Type: type
17
+ }.to_json)
18
+ Response::ProductGroupsResponse.from_json(resp.body)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../response/research_document_response"
3
+
4
+ module ONEAccess
5
+ module API
6
+ class Research < Base
7
+ api_path "/research"
8
+
9
+ def self.document(document_id:, first_name:, last_name:, email:)
10
+ resp = get("document", documentId: document_id, userFirstName: first_name,
11
+ userLastName: last_name, userEmail: email)
12
+ Response::ResearchDocumentResponse.from_json(resp.body)
13
+ end
14
+
15
+ def self.document_by_user_id(document_id:, user_id:)
16
+ resp = get("documentByUserId", documentId: document_id, userId: user_id)
17
+ Response::ResearchDocumentResponse.from_json(resp.body)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../response/user_response"
3
+
4
+ module ONEAccess
5
+ module API
6
+ class User < Base
7
+ api_path "/user"
8
+
9
+ def self.get_by_email(first_name:, last_name:, email:)
10
+ resp = get("getbyemail", userFirstName: first_name, userLastName: last_name, userEmail: email)
11
+ Response::UserResponse.from_json(resp.body)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ class Configuration
4
+ DEFAULT_BASE_URL = "http://ws.oneaccess.io/v1.1"
5
+
6
+ class << self
7
+ attr_accessor :base_url
8
+ attr_accessor :api_key
9
+ attr_accessor :master_api_key
10
+ end
11
+
12
+ self.base_url = DEFAULT_BASE_URL
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/address"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class Address
7
+ attr_accessor :id
8
+ attr_accessor :city
9
+ attr_accessor :country
10
+ attr_accessor :region
11
+ attr_accessor :is_main_address
12
+
13
+ alias main_address? is_main_address
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/city"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class City
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :code
10
+ attr_accessor :description
11
+ attr_accessor :longitude
12
+ attr_accessor :latitude
13
+ attr_accessor :country
14
+ attr_accessor :region
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/country"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class Country
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :code
10
+ attr_accessor :code3
11
+ attr_accessor :description
12
+ attr_accessor :global_region
13
+ attr_accessor :regions
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/global_region"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class GlobalRegion
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :code
10
+ attr_accessor :code3
11
+ attr_accessor :description
12
+ attr_accessor :global_region
13
+ attr_accessor :regions
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/organization_light"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class OrganizationLight
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/product_group"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class ProductGroup
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :description
10
+ attr_accessor :status
11
+ attr_accessor :contributor_org_id
12
+ attr_accessor :type
13
+ attr_accessor :is_default
14
+
15
+ alias is_default? is_default
16
+ alias default? is_default
17
+
18
+ def active?
19
+ status == ProductGroupStatus::ACTIVE
20
+ end
21
+
22
+ def inactive?
23
+ status == ProductGroupStatus::INACTIVE
24
+ end
25
+
26
+ def research?
27
+ type == ProductType::RESEARCH
28
+ end
29
+
30
+ def private_events?
31
+ type == ProductType::PRIVATE_EVENT
32
+ end
33
+
34
+ def events?
35
+ type == ProductType::EVENT
36
+ end
37
+
38
+ def models?
39
+ type == ProductType::MODEL
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/region"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class Region
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :code
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../city"
3
+ require_relative "../country"
4
+ require_relative "../region"
5
+
6
+ module ONEAccess
7
+ module DataObject
8
+ module Representer
9
+ class Address < Representable::Decorator
10
+ include Representable::JSON
11
+
12
+ property :id, as: :Id, type: Integer
13
+ property :is_main_address, as: :IsMainAddress
14
+ property :city, as: :City, decorator: Representer::City, class: DataObject::City
15
+ property :country, as: :Country, decorator: Representer::Country, class: DataObject::Country
16
+ property :region, as: :Region, decorator: Representer::Region, class: DataObject::Region
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../country"
3
+ require_relative "../region"
4
+
5
+ module ONEAccess
6
+ module DataObject
7
+ module Representer
8
+ class City < Representable::Decorator
9
+ include Representable::JSON
10
+
11
+ property :id, as: :Id, type: Integer
12
+ property :name, as: :Name, type: String
13
+ property :code, as: :Code, type: String
14
+ property :description, as: :Description, type: String
15
+ property :longitude, as: :Longitude, type: Float
16
+ property :latitude, as: :Type, type: Float
17
+ property :country, as: :Country, decorator: Representer::Country, class: DataObject::Country
18
+ property :region, as: :Region, decorator: Representer::Region, class: DataObject::Region
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../region"
3
+ require_relative "../global_region"
4
+
5
+ module ONEAccess
6
+ module DataObject
7
+ module Representer
8
+ class Country < Representable::Decorator
9
+ include Representable::JSON
10
+
11
+ property :id, as: :Id, type: Integer
12
+ property :name, as: :Name, type: String
13
+ property :code, as: :Code, type: String
14
+ property :code3, as: :Code3, type: String
15
+ property :description, as: :Description, type: String
16
+ property :global_region, as: :GlobalRegion,
17
+ decorator: Representer::GlobalRegion, class: DataObject::GlobalRegion
18
+ collection :regions, as: :Regions,
19
+ decorator: Representer::Region, class: DataObject::Region
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../country"
3
+ require_relative "../region"
4
+
5
+ # declare country to avoid circular dependency
6
+ # rubocop:disable Style/ClassAndModuleChildren
7
+ class ONEAccess::DataObject::Country; end
8
+ class ONEAccess::DataObject::Representer::Country < Representable::Decorator; end
9
+ # rubocop:enable Style/ClassAndModuleChildren
10
+
11
+ module ONEAccess
12
+ module DataObject
13
+ module Representer
14
+ class GlobalRegion < Representable::Decorator
15
+ include Representable::JSON
16
+
17
+ property :id, as: :Id, type: Integer
18
+ property :name, as: :Name, type: String
19
+ property :code, as: :Code, type: String
20
+ property :description, as: :Description, type: String
21
+ collection :countries, as: :Countries, decorator: Representer::Country, class: DataObject::Country
22
+ collection :regions, as: :Regions, decorator: Representer::Region, class: DataObject::Region
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module DataObject
4
+ module Representer
5
+ class OrganizationLight < Representable::Decorator
6
+ include Representable::JSON
7
+
8
+ property :id, as: :Id, type: Integer
9
+ property :name, as: :Name, type: String
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module DataObject
4
+ module Representer
5
+ class ProductGroup < Representable::Decorator
6
+ include Representable::JSON
7
+
8
+ property :id, as: :Id, type: Integer
9
+ property :name, as: :Name, type: String
10
+ property :description, as: :Description, type: String
11
+ property :status, as: :Status, type: Integer
12
+ property :contributor_org_id, as: :ContributorOrgId, type: Integer
13
+ property :type, as: :Type, type: Integer
14
+ property :is_default, as: :IsDefault
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module DataObject
4
+ module Representer
5
+ class Region < Representable::Decorator
6
+ include Representable::JSON
7
+
8
+ property :id, as: :Id, type: Integer
9
+ property :name, as: :Name, type: String
10
+ property :code, as: :Code, type: String
11
+ property :description, as: :Description, type: String
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../saml_info"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ module Representer
7
+ class ResearchDocumentInfo < Representable::Decorator
8
+ include Representable::JSON
9
+
10
+ property :url, as: :Url, type: String
11
+ property :title, as: :Title, type: String
12
+ property :saml, as: :SAML,
13
+ decorator: Representer::SAMLInfo, class: DataObject::SAMLInfo
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module DataObject
4
+ module Representer
5
+ class SAMLInfo < Representable::Decorator
6
+ include Representable::JSON
7
+
8
+ property :saml_response, as: :SAMLResponse, type: String
9
+ property :sso_login_url, as: :SSOLoginUrl, type: String
10
+ property :use_iframe, as: :UseIframe
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../organization_light"
3
+ require_relative "../address"
4
+
5
+ module ONEAccess
6
+ module DataObject
7
+ module Representer
8
+ class User < Representable::Decorator
9
+ include Representable::JSON
10
+
11
+ property :id, as: :Id, type: Integer
12
+ property :first_name, as: :FirstName, type: String
13
+ property :last_name, as: :LastName, type: String
14
+ property :email, as: :Email, type: String
15
+ property :phone, as: :Phone, type: String
16
+ property :type, as: :Type, type: Integer
17
+ property :active, as: :Active
18
+ property :organization, as: :Organization,
19
+ decorator: Representer::OrganizationLight, class: DataObject::OrganizationLight
20
+ property :address, as: :Address,
21
+ decorator: Representer::Address, class: DataObject::Address
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/research_document_info"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class ResearchDocumentInfo
7
+ attr_accessor :url
8
+ attr_accessor :title
9
+ attr_accessor :saml # instance of SAMLInfo
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/saml_info"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class SAMLInfo
7
+ attr_accessor :saml_response
8
+ attr_accessor :sso_login_url
9
+ attr_accessor :use_iframe
10
+
11
+ alias use_iframe? use_iframe
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/user"
3
+
4
+ module ONEAccess
5
+ module DataObject
6
+ class User
7
+ attr_accessor :id
8
+ attr_accessor :first_name
9
+ attr_accessor :last_name
10
+ attr_accessor :email
11
+ attr_accessor :phone
12
+ attr_accessor :type
13
+ attr_accessor :active
14
+ attr_accessor :reg_status
15
+ attr_accessor :is_broker_administrator
16
+ attr_accessor :organization # Instance of OrganizationLight
17
+ attr_accessor :address
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module APIStatusCode
4
+ SUCCESS = 0
5
+ OBJECT_NOT_FOUND = 2
6
+ BAD_PARAMETER_VALUE = 4
7
+ ACCESS_DENIED = 7
8
+ API_KEY_MISSED = 8
9
+ API_KEY_INVALID = 9
10
+ AUTHENTICATION_FAILED = 10
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module ProductGroupStatus
4
+ ACTIVE = 1
5
+ INACTIVE = 2
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module ProductType
4
+ EVENT = 1
5
+ PRIVATE_EVENT = 2
6
+ RESEARCH = 3
7
+ MODEL = 4
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module Error
4
+ class APIError < StandardError
5
+ attr_reader :http_status_code
6
+ attr_reader :api_status_code
7
+ attr_reader :api_status_message
8
+
9
+ def initialize(http_status_code, api_status_code, api_status_message)
10
+ @http_status_code = http_status_code
11
+ @api_status_code = api_status_code
12
+ @api_status_message = api_status_message
13
+ super(api_status_message)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/api_error"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ class APIError
7
+ attr_accessor :api_status_code
8
+ attr_accessor :api_status_message
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/product_groups_response"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ class ProductGroupsResponse
7
+ extend Serializable
8
+
9
+ represented_by Representer::ProductGroupsResponse
10
+
11
+ attr_accessor :api_status_code
12
+ attr_accessor :total_count
13
+ attr_accessor :has_more_records
14
+ attr_accessor :data
15
+
16
+ alias has_more_records? has_more_records
17
+ alias more_records? has_more_records
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module Response
4
+ module Representer
5
+ class APIError < Representable::Decorator
6
+ include Representable::JSON
7
+
8
+ property :api_status_code, as: :ApiStatusCode
9
+ property :api_status_message, as: :ApiStatusMessage
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../../data_object/product_group"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ module Representer
7
+ class ProductGroupsResponse < Representable::Decorator
8
+ include Representable::JSON
9
+
10
+ property :api_status_code, as: :ApiStatusCode
11
+ property :has_more_records, as: :HasMoreRecords
12
+ property :total_count, as: :TotalCount
13
+ property :api_status_code, as: :ApiStatusCode
14
+ collection :data, as: :Data,
15
+ decorator: DataObject::Representer::ProductGroup,
16
+ class: DataObject::ProductGroup
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../../data_object/research_document_info"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ module Representer
7
+ class ResearchDocumentResponse < Representable::Decorator
8
+ include Representable::JSON
9
+
10
+ property :api_status_code, as: :ApiStatusCode
11
+ property :data, as: :Data,
12
+ decorator: DataObject::Representer::ResearchDocumentInfo,
13
+ class: DataObject::ResearchDocumentInfo
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../../data_object/user"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ module Representer
7
+ class UserResponse < Representable::Decorator
8
+ include Representable::JSON
9
+
10
+ property :api_status_code, as: :ApiStatusCode
11
+ property :data, as: :Data, decorator: DataObject::Representer::User, class: DataObject::User
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/research_document_response"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ class ResearchDocumentResponse
7
+ extend Serializable
8
+
9
+ represented_by Representer::ResearchDocumentResponse
10
+
11
+ attr_accessor :api_status_code
12
+ attr_accessor :data
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require_relative "./representer/user_response"
3
+
4
+ module ONEAccess
5
+ module Response
6
+ class UserResponse
7
+ extend Serializable
8
+
9
+ represented_by Representer::UserResponse
10
+
11
+ attr_accessor :api_status_code
12
+ attr_accessor :data
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module ONEAccess
3
+ module Serializable
4
+ def represented_by(representer_class)
5
+ @representer_class = representer_class
6
+ end
7
+
8
+ def from_json(json)
9
+ obj = new
10
+ @representer_class.new(obj).from_json(json)
11
+ obj
12
+ end
13
+ end
14
+ end
data/lib/oneaccess.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require "representable"
3
+
4
+ require_relative "./oneaccess/configuration"
5
+ require_relative "./oneaccess/serializable"
6
+
7
+ require_relative "./oneaccess/enum/api_status_code"
8
+ require_relative "./oneaccess/enum/product_type"
9
+ require_relative "./oneaccess/enum/product_group_status"
10
+
11
+ require_relative "./oneaccess/api/base"
12
+ require_relative "./oneaccess/api/user"
13
+ require_relative "./oneaccess/api/research"
14
+ require_relative "./oneaccess/api/entitlement/organization/product_group"
15
+ require_relative "./oneaccess/api/entitlement/user/product_group"
16
+
17
+ module ONEAccess
18
+ def self.configure
19
+ raise "expected block for configuration" unless block_given?
20
+ yield Configuration
21
+ end
22
+ end
data/oneaccess.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ Gem::Specification.new do |s|
3
+ s.name = "oneaccess"
4
+ s.version = "0.1.0"
5
+ s.date = "2017-11-01"
6
+ s.summary = "ONEAccess API wrapper"
7
+ s.description = "Easily communicate with ONEAccess API"
8
+ s.homepage = "https://github.com/AlphaExchange/rixml"
9
+ s.authors = ["Alex Correia Santos"]
10
+ s.email = ["alex@alpha-exchange.com"]
11
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
12
+ s.require_paths = ["lib"]
13
+ s.license = "MIT"
14
+
15
+ s.required_ruby_version = ">= 2.2.2"
16
+
17
+ s.add_development_dependency "bundler", "~> 1.12"
18
+ s.add_development_dependency "rspec", "~> 3.6"
19
+ s.add_development_dependency "rake", "~> 11.3"
20
+ s.add_development_dependency "rubocop", "~> 0.45.0"
21
+ s.add_development_dependency "webmock", "~> 3.0.1"
22
+ s.add_development_dependency "simplecov"
23
+ s.add_development_dependency "simplecov-console"
24
+ s.add_development_dependency "byebug"
25
+
26
+ s.add_runtime_dependency "representable", "~> 3.0.4"
27
+ s.add_runtime_dependency "rest-client", "~> 2.0.0"
28
+ s.add_runtime_dependency "multi_json", "~> 1.12.0"
29
+ end
data/release ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ cp oneaccess.gemspec oneaccess.gemspec.backup
3
+ sed -i.bak s/0.0.0/$1/g oneaccess.gemspec
4
+ sed -i.bak s/2001-01-01/`date +%Y-%m-%d`/g oneaccess.gemspec
5
+ gem build oneaccess.gemspec
6
+ mv oneaccess.gemspec.backup oneaccess.gemspec
7
+ gem push oneaccess-$1.gem
8
+ git tag -a v$1 -m "Release v$1"
9
+ git push origin --tags
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oneaccess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Correia Santos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-27 00:00:00.000000000 Z
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,8 +170,59 @@ email:
170
170
  executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
- files: []
174
- homepage: https://github.com/AlphaExchange/oneaccess-rb
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - Gemfile
178
+ - Gemfile.lock
179
+ - README.md
180
+ - Rakefile
181
+ - circle.yml
182
+ - console
183
+ - lib/oneaccess.rb
184
+ - lib/oneaccess/api/base.rb
185
+ - lib/oneaccess/api/entitlement/organization/product_group.rb
186
+ - lib/oneaccess/api/entitlement/user/product_group.rb
187
+ - lib/oneaccess/api/research.rb
188
+ - lib/oneaccess/api/user.rb
189
+ - lib/oneaccess/configuration.rb
190
+ - lib/oneaccess/data_object/address.rb
191
+ - lib/oneaccess/data_object/city.rb
192
+ - lib/oneaccess/data_object/country.rb
193
+ - lib/oneaccess/data_object/global_region.rb
194
+ - lib/oneaccess/data_object/organization_light.rb
195
+ - lib/oneaccess/data_object/product_group.rb
196
+ - lib/oneaccess/data_object/region.rb
197
+ - lib/oneaccess/data_object/representer/address.rb
198
+ - lib/oneaccess/data_object/representer/city.rb
199
+ - lib/oneaccess/data_object/representer/country.rb
200
+ - lib/oneaccess/data_object/representer/global_region.rb
201
+ - lib/oneaccess/data_object/representer/organization_light.rb
202
+ - lib/oneaccess/data_object/representer/product_group.rb
203
+ - lib/oneaccess/data_object/representer/region.rb
204
+ - lib/oneaccess/data_object/representer/research_document_info.rb
205
+ - lib/oneaccess/data_object/representer/saml_info.rb
206
+ - lib/oneaccess/data_object/representer/user.rb
207
+ - lib/oneaccess/data_object/research_document_info.rb
208
+ - lib/oneaccess/data_object/saml_info.rb
209
+ - lib/oneaccess/data_object/user.rb
210
+ - lib/oneaccess/enum/api_status_code.rb
211
+ - lib/oneaccess/enum/product_group_status.rb
212
+ - lib/oneaccess/enum/product_type.rb
213
+ - lib/oneaccess/error/api_error.rb
214
+ - lib/oneaccess/response/api_error.rb
215
+ - lib/oneaccess/response/product_groups_response.rb
216
+ - lib/oneaccess/response/representer/api_error.rb
217
+ - lib/oneaccess/response/representer/product_groups_response.rb
218
+ - lib/oneaccess/response/representer/research_document_response.rb
219
+ - lib/oneaccess/response/representer/user_response.rb
220
+ - lib/oneaccess/response/research_document_response.rb
221
+ - lib/oneaccess/response/user_response.rb
222
+ - lib/oneaccess/serializable.rb
223
+ - oneaccess.gemspec
224
+ - release
225
+ homepage: https://github.com/AlphaExchange/rixml
175
226
  licenses:
176
227
  - MIT
177
228
  metadata: {}