clx_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +55 -0
  7. data/Rakefile +7 -0
  8. data/clx_api.gemspec +26 -0
  9. data/doc/CLX.html +305 -0
  10. data/doc/CLX/API.html +1491 -0
  11. data/doc/CLX/CLXAPIException.html +411 -0
  12. data/doc/CLX/CLXException.html +134 -0
  13. data/doc/CLX/HTTPAdapter.html +1294 -0
  14. data/doc/CLX/HTTPClient.html +1058 -0
  15. data/doc/ClxApi.html +141 -0
  16. data/doc/_index.html +161 -0
  17. data/doc/class_list.html +58 -0
  18. data/doc/css/common.css +1 -0
  19. data/doc/css/full_list.css +57 -0
  20. data/doc/css/style.css +339 -0
  21. data/doc/file.README.html +112 -0
  22. data/doc/file_list.html +60 -0
  23. data/doc/frames.html +26 -0
  24. data/doc/index.html +112 -0
  25. data/doc/js/app.js +219 -0
  26. data/doc/js/full_list.js +181 -0
  27. data/doc/js/jquery.js +4 -0
  28. data/doc/method_list.html +279 -0
  29. data/doc/top-level-namespace.html +112 -0
  30. data/examples/get_gateway_by_id.rb +16 -0
  31. data/examples/get_gateways.rb +18 -0
  32. data/examples/get_operator_by_id.rb +21 -0
  33. data/examples/get_operators.rb +23 -0
  34. data/examples/get_price_entries_by_gateway_id.rb +19 -0
  35. data/examples/get_price_entries_by_gateway_id_and_operator_id.rb +17 -0
  36. data/examples/get_price_entries_by_gateway_id_and_operator_id_and_date.rb +18 -0
  37. data/examples/readme.md +167 -0
  38. data/lib/clx_api.rb +35 -0
  39. data/lib/clx_api/api.rb +132 -0
  40. data/lib/clx_api/exceptions/clx_api_exception.rb +25 -0
  41. data/lib/clx_api/exceptions/clx_exception.rb +8 -0
  42. data/lib/clx_api/http_adapter.rb +129 -0
  43. data/lib/clx_api/http_client.rb +163 -0
  44. data/lib/clx_api/version.rb +4 -0
  45. data/test/adapter/test_adapter.rb +67 -0
  46. data/test/api_test.rb +306 -0
  47. data/test/http_adapter_test.rb +211 -0
  48. data/test/http_client_test.rb +173 -0
  49. data/test/test_helper.rb +7 -0
  50. metadata +168 -0
@@ -0,0 +1,173 @@
1
+ require 'test_helper'
2
+
3
+ class HTTPClientTest < MiniTest::Test
4
+
5
+ def setup
6
+ http_adapter = CLX::TestAdapter.new
7
+ http_adapter.set_auth('username', 'password')
8
+ @base_url = 'http://base.url.org/api'
9
+ @client = CLX::HTTPClient.new @base_url, http_adapter
10
+ end
11
+
12
+ def test_initializer
13
+ assert_instance_of CLX::HTTPClient, @client
14
+ end
15
+
16
+ def test_request_resource_list_returns_array_of_open_struct
17
+ response = OpenStruct.new(
18
+ body: '[
19
+ {"id":1,"name":"Foo","network":"Foonetwork","uniqueName":"Foo uniquq","isoCountryCode":"8","operationalState":"active","operationalStatDate":"-0001-11-30 00:00:00","numberOfSubscribers":0},
20
+ {"id":1058,"name":"Bar mobile","network":"Bar Mobile","uniqueName":"Foo Mobile-unique","isoCountryCode":"8","operationalState":"active","operationalStatDate":"-0001-11-30 00:00:00","numberOfSubscribers":0}
21
+ ]',
22
+ code: 200
23
+ )
24
+ @client.http_adapter.response = response
25
+ path = '/operator'
26
+ full_url = @base_url + path
27
+
28
+ result = @client.get(path)
29
+
30
+ assert_equal result.length, 2
31
+ assert_equal result[0].id, 1
32
+ assert_equal @client.http_adapter.request_url, full_url
33
+ assert_equal @client.http_adapter.request_method, 'GET'
34
+ end
35
+
36
+ def test_request_single_resource_returns_open_struct
37
+ response = OpenStruct.new(
38
+ body: '{"id":1,"name":"Foo","network":"Foonetwork","uniqueName":"Foo uniquq","isoCountryCode":"8","operationalState":"active","operationalStatDate":"-0001-11-30 00:00:00","numberOfSubscribers":0}',
39
+ code: 200
40
+ )
41
+ @client.http_adapter.response = response
42
+ path = '/operator/1'
43
+ full_url = @base_url + path
44
+
45
+ result = @client.get(path)
46
+
47
+ assert_equal result.id, 1
48
+ assert_equal @client.http_adapter.request_url, full_url
49
+ assert_equal @client.http_adapter.request_method, 'GET'
50
+ end
51
+
52
+ def test_get_request_to_resource_that_does_not_exist_raises_clx_exception_
53
+ response = OpenStruct.new(
54
+ body: '{"error":{"message": "No operator with id: 9999", "code": 3001}}',
55
+ code: 404
56
+ )
57
+ @client.http_adapter.response = response
58
+ path = '/operator/9999'
59
+ full_url = @base_url + path
60
+
61
+ assert_raises CLX::CLXAPIException do
62
+ #test http-code == 404
63
+ result = @client.get(path)
64
+ end
65
+ assert_equal @client.http_adapter.request_url, full_url
66
+ assert_equal @client.http_adapter.request_method, 'GET'
67
+ end
68
+
69
+ def test_post_returns_data_hash_as_open_struct
70
+ data = {id: 1, key: 'value'}
71
+ response = OpenStruct.new(
72
+ body: data.to_json,
73
+ code: 201
74
+ )
75
+ @client.http_adapter.response = response
76
+ path = '/post-path'
77
+ full_url = @base_url + path
78
+
79
+ result = @client.post(path, data)
80
+
81
+ assert_equal data[:id], result.id
82
+ assert_equal data[:key], result.key
83
+ assert_equal @client.http_adapter.request_url, full_url
84
+ assert_equal @client.http_adapter.request_method, 'POST'
85
+ end
86
+
87
+ def test_put_returns_modified_data_hash_as_open_struct
88
+ data = {id: 1, key: 'value'}
89
+ data[:key] = 'new value'
90
+ response = OpenStruct.new(
91
+ body: data.to_json,
92
+ code: 200
93
+ )
94
+ @client.http_adapter.response = response
95
+ path = '/put-path'
96
+ full_url = @base_url + path
97
+
98
+ result = @client.put(path, data)
99
+
100
+ assert_equal data[:id], result.id
101
+ assert_equal data[:key], result.key
102
+ assert_equal @client.http_adapter.request_url, full_url
103
+ assert_equal @client.http_adapter.request_method, 'PUT'
104
+ end
105
+
106
+ def test_delete_returns_empty_open_struct
107
+ response = OpenStruct.new(
108
+ body: '{}',
109
+ code: 204
110
+ )
111
+ @client.http_adapter.response = response
112
+ path = '/delete-path'
113
+ full_url = @base_url + path
114
+
115
+ result = @client.delete(path)
116
+
117
+ assert_empty result.to_h
118
+ assert_equal @client.http_adapter.request_url, full_url
119
+ assert_equal @client.http_adapter.request_method, 'DELETE'
120
+ end
121
+
122
+ def test_parser_with_invalid_json_raises_clx_exception
123
+ response = OpenStruct.new(
124
+ body: '{not_valid_json \not :at all',
125
+ code: 200
126
+ )
127
+ @client.http_adapter.response = response
128
+
129
+ path = '/invalid-json-response'
130
+ full_url = @base_url + path
131
+
132
+ assert_raises CLX::CLXException do
133
+ @client.get(path)
134
+ end
135
+ assert_equal @client.http_adapter.request_url, full_url
136
+ assert_equal @client.http_adapter.request_method, 'GET'
137
+ end
138
+
139
+ def test_reponse_with_unknown_http_status_code_with_error_raises_clx_api_exception
140
+ response = OpenStruct.new(
141
+ body: '{"message": "strage error", "code": 1234}',
142
+ code: 410
143
+ )
144
+ @client.http_adapter.response = response
145
+
146
+ path = '/invalid-unknown-http-code-with-error'
147
+ full_url = @base_url + path
148
+
149
+ assert_raises CLX::CLXAPIException do
150
+ @client.get(path)
151
+ end
152
+ assert_equal @client.http_adapter.request_url, full_url
153
+ assert_equal @client.http_adapter.request_method, 'GET'
154
+ end
155
+
156
+ def test_response_with_unknown_http_status_code_but_no_errors_raises_clx_api_exception
157
+ response = OpenStruct.new(
158
+ body: '{}',
159
+ code: 410
160
+ )
161
+ @client.http_adapter.response = response
162
+
163
+ path = '/invalid-unknown-http-code-without-error'
164
+ full_url = @base_url + path
165
+
166
+ assert_raises CLX::CLXAPIException do
167
+ @client.get(path)
168
+ end
169
+ assert_equal @client.http_adapter.request_url, full_url
170
+ assert_equal @client.http_adapter.request_method, 'GET'
171
+ end
172
+
173
+ end
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ require 'json'
3
+ SimpleCov.start
4
+
5
+ require 'clx_api'
6
+ require 'adapter/test_adapter'
7
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clx_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andreas Fridlund
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.7.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.7.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.0
83
+ description: Ruby Gem for CLX Networks API.
84
+ email:
85
+ - afrxx09@student.lnu.se
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".yardopts"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - clx_api.gemspec
97
+ - doc/CLX.html
98
+ - doc/CLX/API.html
99
+ - doc/CLX/CLXAPIException.html
100
+ - doc/CLX/CLXException.html
101
+ - doc/CLX/HTTPAdapter.html
102
+ - doc/CLX/HTTPClient.html
103
+ - doc/ClxApi.html
104
+ - doc/_index.html
105
+ - doc/class_list.html
106
+ - doc/css/common.css
107
+ - doc/css/full_list.css
108
+ - doc/css/style.css
109
+ - doc/file.README.html
110
+ - doc/file_list.html
111
+ - doc/frames.html
112
+ - doc/index.html
113
+ - doc/js/app.js
114
+ - doc/js/full_list.js
115
+ - doc/js/jquery.js
116
+ - doc/method_list.html
117
+ - doc/top-level-namespace.html
118
+ - examples/get_gateway_by_id.rb
119
+ - examples/get_gateways.rb
120
+ - examples/get_operator_by_id.rb
121
+ - examples/get_operators.rb
122
+ - examples/get_price_entries_by_gateway_id.rb
123
+ - examples/get_price_entries_by_gateway_id_and_operator_id.rb
124
+ - examples/get_price_entries_by_gateway_id_and_operator_id_and_date.rb
125
+ - examples/readme.md
126
+ - lib/clx_api.rb
127
+ - lib/clx_api/api.rb
128
+ - lib/clx_api/exceptions/clx_api_exception.rb
129
+ - lib/clx_api/exceptions/clx_exception.rb
130
+ - lib/clx_api/http_adapter.rb
131
+ - lib/clx_api/http_client.rb
132
+ - lib/clx_api/version.rb
133
+ - test/adapter/test_adapter.rb
134
+ - test/api_test.rb
135
+ - test/http_adapter_test.rb
136
+ - test/http_client_test.rb
137
+ - test/test_helper.rb
138
+ homepage: https://clxnetworks.com/
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.4.6
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: CLX Networks API Gem.
162
+ test_files:
163
+ - test/adapter/test_adapter.rb
164
+ - test/api_test.rb
165
+ - test/http_adapter_test.rb
166
+ - test/http_client_test.rb
167
+ - test/test_helper.rb
168
+ has_rdoc: