alman 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +8 -0
  5. data/README.md +103 -0
  6. data/Rakefile +8 -0
  7. data/VERSION +1 -0
  8. data/alman.gemspec +29 -0
  9. data/bin/alman-console +7 -0
  10. data/gemfiles/default-with-activesupport.gemfile +10 -0
  11. data/gemfiles/json.gemfile +12 -0
  12. data/gemfiles/yajl.gemfile +12 -0
  13. data/lib/alman.rb +68 -0
  14. data/lib/alman/apibits/api_client.rb +28 -0
  15. data/lib/alman/apibits/api_endpoint.rb +11 -0
  16. data/lib/alman/apibits/api_list.rb +88 -0
  17. data/lib/alman/apibits/api_method.rb +95 -0
  18. data/lib/alman/apibits/api_object.rb +52 -0
  19. data/lib/alman/apibits/api_resource.rb +139 -0
  20. data/lib/alman/apibits/headers_builder.rb +47 -0
  21. data/lib/alman/apibits/params_builder.rb +27 -0
  22. data/lib/alman/apibits/path_builder.rb +38 -0
  23. data/lib/alman/apibits/requester.rb +104 -0
  24. data/lib/alman/apibits/util.rb +51 -0
  25. data/lib/alman/clients/default_client.rb +31 -0
  26. data/lib/alman/endpoints/bookings_endpoint.rb +36 -0
  27. data/lib/alman/endpoints/calendar_vacancies_endpoint.rb +35 -0
  28. data/lib/alman/endpoints/calendars_endpoint.rb +48 -0
  29. data/lib/alman/endpoints/vacancies_endpoint.rb +27 -0
  30. data/lib/alman/endpoints/vacancy_bookings_endpoint.rb +11 -0
  31. data/lib/alman/errors/alman_error.rb +13 -0
  32. data/lib/alman/errors/api_connection_error.rb +4 -0
  33. data/lib/alman/errors/api_error.rb +35 -0
  34. data/lib/alman/errors/authentication_error.rb +4 -0
  35. data/lib/alman/resources/booking.rb +62 -0
  36. data/lib/alman/resources/calendar.rb +65 -0
  37. data/lib/alman/resources/vacancy.rb +48 -0
  38. data/lib/alman/version.rb +3 -0
  39. data/test/alman/api_client_test.rb +51 -0
  40. data/test/alman/api_endpoint_test.rb +13 -0
  41. data/test/alman/api_list_test.rb +49 -0
  42. data/test/alman/api_method_test.rb +78 -0
  43. data/test/alman/headers_builder_test.rb +28 -0
  44. data/test/alman/params_builder_test.rb +57 -0
  45. data/test/alman/path_builder_test.rb +50 -0
  46. data/test/alman/requester_test.rb +86 -0
  47. data/test/alman/util_test.rb +51 -0
  48. data/test/test_data.rb +72 -0
  49. data/test/test_helper.rb +41 -0
  50. metadata +208 -0
data/test/test_data.rb ADDED
@@ -0,0 +1,72 @@
1
+ module Alman
2
+ module TestData
3
+
4
+ def test_response(body, code=200)
5
+ # When an exception is raised, restclient clobbers method_missing. Hence we
6
+ # can't just use the stubs interface.
7
+ body = JSON.generate(body) if !(body.kind_of? String)
8
+ m = mock
9
+ m.instance_variable_set('@alman_values', { :body => body, :code => code })
10
+ def m.body; @alman_values[:body]; end
11
+ def m.code; @alman_values[:code]; end
12
+ m
13
+ end
14
+
15
+ def test_mock_resource
16
+ {
17
+ :object => 'mock_resource',
18
+ :name => 'test mr name',
19
+ :nested => {
20
+ :id => 'test_nested_id',
21
+ :object => 'nested_resource',
22
+ :price => 500
23
+ },
24
+ :nested_alt_id => 'nested_alt_id',
25
+ :nested_with => {
26
+ :id => 'nested_with_id',
27
+ :price => 500
28
+ },
29
+ :thash => { :some_key => "some value" },
30
+ :tarray => ["abc", "xyz"],
31
+ :id => 'test_mock_resource_id'
32
+ }
33
+ end
34
+
35
+ def test_mock_resource_list
36
+ {
37
+ :object => 'list',
38
+ :data => [test_mock_resource, test_mock_resource, test_mock_resource],
39
+ }
40
+ end
41
+
42
+
43
+ # Errors
44
+ def test_api_error
45
+ {
46
+ :error => {
47
+ :type => "api_error"
48
+ }
49
+ }
50
+ end
51
+
52
+ def test_invalid_api_key_error
53
+ {
54
+ :error => {
55
+ :type => "invalid_request_error",
56
+ :message => "Invalid API Key provided: invalid"
57
+ }
58
+ }
59
+ end
60
+
61
+ def test_missing_id_error
62
+ {
63
+ :error => {
64
+ :param => "id",
65
+ :type => "invalid_request_error",
66
+ :message => "Missing id"
67
+ }
68
+ }
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,41 @@
1
+ require 'alman'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'stringio'
5
+ require 'shoulda'
6
+ require File.expand_path('../test_data', __FILE__)
7
+ # require File.expand_path('../mock_resource', __FILE__)
8
+
9
+ # monkeypatch request methods
10
+ module Alman
11
+ class << self
12
+ attr_accessor :mock_rest_client
13
+ end
14
+
15
+ module Requester
16
+ def self.request(method, url, params, headers)
17
+ case method
18
+ when :get then Alman::mock_rest_client.get(url, headers, params)
19
+ when :put then Alman::mock_rest_client.put(url, headers, params)
20
+ when :post then Alman::mock_rest_client.post(url, headers, params)
21
+ when :delete then Alman::mock_rest_client.delete(url, headers, params)
22
+ else
23
+ raise "Invalid method"
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ class ::Test::Unit::TestCase
30
+ include Alman::TestData
31
+ include Mocha
32
+
33
+ setup do
34
+ @mock = mock
35
+ Alman.mock_rest_client = @mock
36
+ end
37
+
38
+ teardown do
39
+ Alman.mock_rest_client = nil
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,208 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Apibits.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-31 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.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mime-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.25'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '1.25'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.8.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: mocha
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.13.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.13.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: shoulda
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 3.4.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 3.4.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: test-unit
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Alman is a calendar scheduling API.
118
+ email:
119
+ - libraries@apibits.com
120
+ executables:
121
+ - alman-console
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - ".gitignore"
126
+ - ".travis.yml"
127
+ - Gemfile
128
+ - README.md
129
+ - Rakefile
130
+ - VERSION
131
+ - alman.gemspec
132
+ - bin/alman-console
133
+ - gemfiles/default-with-activesupport.gemfile
134
+ - gemfiles/json.gemfile
135
+ - gemfiles/yajl.gemfile
136
+ - lib/alman.rb
137
+ - lib/alman/apibits/api_client.rb
138
+ - lib/alman/apibits/api_endpoint.rb
139
+ - lib/alman/apibits/api_list.rb
140
+ - lib/alman/apibits/api_method.rb
141
+ - lib/alman/apibits/api_object.rb
142
+ - lib/alman/apibits/api_resource.rb
143
+ - lib/alman/apibits/headers_builder.rb
144
+ - lib/alman/apibits/params_builder.rb
145
+ - lib/alman/apibits/path_builder.rb
146
+ - lib/alman/apibits/requester.rb
147
+ - lib/alman/apibits/util.rb
148
+ - lib/alman/clients/default_client.rb
149
+ - lib/alman/endpoints/bookings_endpoint.rb
150
+ - lib/alman/endpoints/calendar_vacancies_endpoint.rb
151
+ - lib/alman/endpoints/calendars_endpoint.rb
152
+ - lib/alman/endpoints/vacancies_endpoint.rb
153
+ - lib/alman/endpoints/vacancy_bookings_endpoint.rb
154
+ - lib/alman/errors/alman_error.rb
155
+ - lib/alman/errors/api_connection_error.rb
156
+ - lib/alman/errors/api_error.rb
157
+ - lib/alman/errors/authentication_error.rb
158
+ - lib/alman/resources/booking.rb
159
+ - lib/alman/resources/calendar.rb
160
+ - lib/alman/resources/vacancy.rb
161
+ - lib/alman/version.rb
162
+ - test/alman/api_client_test.rb
163
+ - test/alman/api_endpoint_test.rb
164
+ - test/alman/api_list_test.rb
165
+ - test/alman/api_method_test.rb
166
+ - test/alman/headers_builder_test.rb
167
+ - test/alman/params_builder_test.rb
168
+ - test/alman/path_builder_test.rb
169
+ - test/alman/requester_test.rb
170
+ - test/alman/util_test.rb
171
+ - test/test_data.rb
172
+ - test/test_helper.rb
173
+ homepage: http://almanapi.com/docs
174
+ licenses:
175
+ - MIT
176
+ metadata: {}
177
+ post_install_message:
178
+ rdoc_options: []
179
+ require_paths:
180
+ - lib
181
+ required_ruby_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 2.4.5
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Ruby bindings for Alman API
197
+ test_files:
198
+ - test/alman/api_client_test.rb
199
+ - test/alman/api_endpoint_test.rb
200
+ - test/alman/api_list_test.rb
201
+ - test/alman/api_method_test.rb
202
+ - test/alman/headers_builder_test.rb
203
+ - test/alman/params_builder_test.rb
204
+ - test/alman/path_builder_test.rb
205
+ - test/alman/requester_test.rb
206
+ - test/alman/util_test.rb
207
+ - test/test_data.rb
208
+ - test/test_helper.rb