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
@@ -0,0 +1,31 @@
1
+ module Alman
2
+ class DefaultClient < ApiClient
3
+
4
+ def initialize(api_key)
5
+ self.refresh_from(api_key)
6
+ end
7
+
8
+ def refresh_from(api_key)
9
+ headers = {
10
+ :Accept => "application/json",
11
+ :"Content-Type" => "application/json",
12
+ :Authorization => api_key,
13
+ }
14
+ params = {}
15
+ super(headers, params)
16
+ end
17
+
18
+ def calendars
19
+ @calendars ||= CalendarsEndpoint.new(self)
20
+ end
21
+
22
+ def vacancies
23
+ @vacancies ||= VacanciesEndpoint.new(self)
24
+ end
25
+
26
+ def bookings
27
+ @bookings ||= BookingsEndpoint.new(self)
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module Alman
2
+ class BookingsEndpoint < ApiEndpoint
3
+
4
+ def new(id)
5
+ Booking.new({:id => id}, nil, @client)
6
+ end
7
+
8
+ def retrieve(booking_id, params={}, headers={})
9
+ params = ParamsBuilder.merge({
10
+ :booking_id => booking_id,
11
+ }, params)
12
+ method = ApiMethod.new(:get, "/bookings/:booking_id", params, headers, @parent)
13
+ json = @client.execute(method)
14
+ Booking.new(json, method)
15
+ end
16
+
17
+ def delete(booking_id, params={}, headers={})
18
+ params = ParamsBuilder.merge({
19
+ :booking_id => booking_id,
20
+ }, params)
21
+ method = ApiMethod.new(:delete, "/bookings/:booking_id", params, headers, @parent)
22
+ json = @client.execute(method)
23
+ Booking.new(json, method)
24
+ end
25
+
26
+ def update(booking_id, params={}, headers={})
27
+ params = ParamsBuilder.merge({
28
+ :booking_id => booking_id,
29
+ }, params)
30
+ method = ApiMethod.new(:put, "/bookings/:booking_id", params, headers, @parent)
31
+ json = @client.execute(method)
32
+ Booking.new(json, method)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module Alman
2
+ class CalendarVacanciesEndpoint < ApiEndpoint
3
+
4
+ def all(params={}, headers={})
5
+ method = ApiMethod.new(:get, "/calendars/:id/vacancies", params, headers, @parent)
6
+ json = @client.execute(method)
7
+ ApiList.new(:Vacancy, json, method)
8
+ end
9
+
10
+ def all_within(params={}, headers={})
11
+ method = ApiMethod.new(:get, "/calendars/:id/vacancies/within", params, headers, @parent)
12
+ json = @client.execute(method)
13
+ ApiList.new(:Vacancy, json, method)
14
+ end
15
+
16
+ def create(params={}, headers={})
17
+ method = ApiMethod.new(:post, "/calendars/:id/vacancies", params, headers, @parent)
18
+ json = @client.execute(method)
19
+ Vacancy.new(json, method)
20
+ end
21
+
22
+ def create_range(params={}, headers={})
23
+ method = ApiMethod.new(:post, "/calendars/:id/vacancies/range", params, headers, @parent)
24
+ json = @client.execute(method)
25
+ ApiList.new(:Vacancy, json, method)
26
+ end
27
+
28
+ def delete_overlap(params={}, headers={})
29
+ method = ApiMethod.new(:delete, "/calendars/:id/vacancies/overlap", params, headers, @parent)
30
+ json = @client.execute(method)
31
+ ApiList.new(:Vacancy, json, method)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ module Alman
2
+ class CalendarsEndpoint < ApiEndpoint
3
+
4
+ def new(id)
5
+ Calendar.new({:id => id}, nil, @client)
6
+ end
7
+
8
+ def all(params={}, headers={})
9
+ method = ApiMethod.new(:get, "/calendars", params, headers, @parent)
10
+ json = @client.execute(method)
11
+ ApiList.new(:Calendar, json, method)
12
+ end
13
+
14
+ def retrieve(calendar_id, params={}, headers={})
15
+ params = ParamsBuilder.merge({
16
+ :calendar_id => calendar_id,
17
+ }, params)
18
+ method = ApiMethod.new(:get, "/calendars/:calendar_id", params, headers, @parent)
19
+ json = @client.execute(method)
20
+ Calendar.new(json, method)
21
+ end
22
+
23
+ def delete(calendar_id, params={}, headers={})
24
+ params = ParamsBuilder.merge({
25
+ :calendar_id => calendar_id,
26
+ }, params)
27
+ method = ApiMethod.new(:delete, "/calendars/:calendar_id", params, headers, @parent)
28
+ json = @client.execute(method)
29
+ Calendar.new(json, method)
30
+ end
31
+
32
+ def update(calendar_id, params={}, headers={})
33
+ params = ParamsBuilder.merge({
34
+ :calendar_id => calendar_id,
35
+ }, params)
36
+ method = ApiMethod.new(:put, "/calendars/:calendar_id", params, headers, @parent)
37
+ json = @client.execute(method)
38
+ Calendar.new(json, method)
39
+ end
40
+
41
+ def create(params={}, headers={})
42
+ method = ApiMethod.new(:post, "/calendars", params, headers, @parent)
43
+ json = @client.execute(method)
44
+ Calendar.new(json, method)
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ module Alman
2
+ class VacanciesEndpoint < ApiEndpoint
3
+
4
+ def new(id)
5
+ Vacancy.new({:id => id}, nil, @client)
6
+ end
7
+
8
+ def retrieve(vacancy_id, params={}, headers={})
9
+ params = ParamsBuilder.merge({
10
+ :vacancy_id => vacancy_id,
11
+ }, params)
12
+ method = ApiMethod.new(:get, "/vacancies/:vacancy_id", params, headers, @parent)
13
+ json = @client.execute(method)
14
+ Vacancy.new(json, method)
15
+ end
16
+
17
+ def delete(vacancy_id, params={}, headers={})
18
+ params = ParamsBuilder.merge({
19
+ :vacancy_id => vacancy_id,
20
+ }, params)
21
+ method = ApiMethod.new(:delete, "/vacancies/:vacancy_id", params, headers, @parent)
22
+ json = @client.execute(method)
23
+ Vacancy.new(json, method)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Alman
2
+ class VacancyBookingsEndpoint < ApiEndpoint
3
+
4
+ def create(params={}, headers={})
5
+ method = ApiMethod.new(:post, "/vacancies/:id/bookings", params, headers, @parent)
6
+ json = @client.execute(method)
7
+ Booking.new(json, method)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Alman
2
+ class AlmanError < StandardError
3
+ attr_reader :message
4
+
5
+ def initialize(message=nil)
6
+ @message = message
7
+ end
8
+
9
+ def to_s
10
+ "#{@message}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Alman
2
+ class ApiConnectionError < ApiError
3
+ end
4
+ end
@@ -0,0 +1,35 @@
1
+ module Alman
2
+ class ApiError < AlmanError
3
+ attr_reader :api_method
4
+
5
+ def initialize(message=nil, api_method=nil)
6
+ @message = message
7
+ @api_method = api_method
8
+ end
9
+
10
+ def code
11
+ @api_method.response_code if @api_method
12
+ end
13
+
14
+ def body
15
+ @api_method.response_body if @api_method
16
+ end
17
+
18
+ def json
19
+ begin
20
+ if @api_method
21
+ hash = @api_method.response_json
22
+ return ApiObject.construct(hash)
23
+ end
24
+ rescue ApiError
25
+ nil
26
+ end
27
+ end
28
+
29
+ def to_s
30
+ prefix = code.nil? ? "" : "(Status #{code}) "
31
+ "#{prefix}#{@message}"
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,4 @@
1
+ module Alman
2
+ class AuthenticationError < ApiError
3
+ end
4
+ end
@@ -0,0 +1,62 @@
1
+ module Alman
2
+ class Booking < ApiResource
3
+ attr_accessor :created_at
4
+ attr_accessor :created_at_rfc822
5
+ attr_accessor :end_at
6
+ attr_accessor :end_at_rfc822
7
+ attr_accessor :id
8
+ attr_accessor :meta
9
+ attr_accessor :object
10
+ attr_accessor :start_at
11
+ attr_accessor :start_at_rfc822
12
+ attr_accessor :updated_at
13
+ attr_accessor :updated_at_rfc822
14
+
15
+ def self.all(params={}, headers={})
16
+ res = client.bookings.all(params, headers)
17
+ res
18
+ end
19
+
20
+ def self.retrieve(booking_id, params={}, headers={})
21
+ res = client.bookings.retrieve(booking_id, params, headers)
22
+ res
23
+ end
24
+
25
+ def self.update(booking_id, params={}, headers={})
26
+ res = client.bookings.update(booking_id, params, headers)
27
+ res
28
+ end
29
+
30
+ def refresh(params={}, headers={})
31
+ res = client.bookings.retrieve(id, params, headers)
32
+ self.refresh_from(res.json, res.api_method, res.client)
33
+ end
34
+
35
+ def delete(params={}, headers={})
36
+ res = client.bookings.delete(id, params, headers)
37
+ self.refresh_from(res.json, res.api_method, res.client)
38
+ end
39
+
40
+ def save(params={}, headers={})
41
+ params = ParamsBuilder.merge(api_attributes, params)
42
+ res = client.bookings.update(id, params, headers)
43
+ self.refresh_from(res.json, res.api_method, res.client)
44
+ end
45
+
46
+ # Everything below here is used behind the scenes.
47
+ ApiResource.register_api_subclass(self, "booking")
48
+ @api_attributes = {
49
+ :created_at => {},
50
+ :created_at_rfc822 => {},
51
+ :end_at => {},
52
+ :end_at_rfc822 => {},
53
+ :id => {},
54
+ :meta => { :editable => true },
55
+ :object => {},
56
+ :start_at => {},
57
+ :start_at_rfc822 => {},
58
+ :updated_at => {},
59
+ :updated_at_rfc822 => {},
60
+ }
61
+ end
62
+ end
@@ -0,0 +1,65 @@
1
+ module Alman
2
+ class Calendar < ApiResource
3
+ attr_accessor :created_at
4
+ attr_accessor :created_at_rfc822
5
+ attr_accessor :details
6
+ attr_accessor :id
7
+ attr_accessor :name
8
+ attr_accessor :object
9
+ attr_accessor :updated_at
10
+ attr_accessor :updated_at_rfc822
11
+
12
+ def self.all(params={}, headers={})
13
+ res = client.calendars.all(params, headers)
14
+ res
15
+ end
16
+
17
+ def self.retrieve(calendar_id, params={}, headers={})
18
+ res = client.calendars.retrieve(calendar_id, params, headers)
19
+ res
20
+ end
21
+
22
+ def self.update(calendar_id, params={}, headers={})
23
+ res = client.calendars.update(calendar_id, params, headers)
24
+ res
25
+ end
26
+
27
+ def self.create(params={}, headers={})
28
+ res = client.calendars.create(params, headers)
29
+ res
30
+ end
31
+
32
+ def refresh(params={}, headers={})
33
+ res = client.calendars.retrieve(id, params, headers)
34
+ self.refresh_from(res.json, res.api_method, res.client)
35
+ end
36
+
37
+ def delete(params={}, headers={})
38
+ res = client.calendars.delete(id, params, headers)
39
+ self.refresh_from(res.json, res.api_method, res.client)
40
+ end
41
+
42
+ def vacancies()
43
+ CalendarVacanciesEndpoint.new(client, self)
44
+ end
45
+
46
+ def save(params={}, headers={})
47
+ params = ParamsBuilder.merge(api_attributes, params)
48
+ res = client.calendars.update(id, params, headers)
49
+ self.refresh_from(res.json, res.api_method, res.client)
50
+ end
51
+
52
+ # Everything below here is used behind the scenes.
53
+ ApiResource.register_api_subclass(self, "calendar")
54
+ @api_attributes = {
55
+ :created_at => {},
56
+ :created_at_rfc822 => {},
57
+ :details => { :editable => true },
58
+ :id => {},
59
+ :name => { :editable => true },
60
+ :object => {},
61
+ :updated_at => {},
62
+ :updated_at_rfc822 => {},
63
+ }
64
+ end
65
+ end
@@ -0,0 +1,48 @@
1
+ module Alman
2
+ class Vacancy < ApiResource
3
+ attr_accessor :created_at
4
+ attr_accessor :created_at_rfc822
5
+ attr_accessor :end_at
6
+ attr_accessor :end_at_rfc822
7
+ attr_accessor :id
8
+ attr_accessor :object
9
+ attr_accessor :start_at
10
+ attr_accessor :start_at_rfc822
11
+ attr_accessor :updated_at
12
+ attr_accessor :updated_at_rfc822
13
+
14
+ def self.retrieve(vacancy_id, params={}, headers={})
15
+ res = client.vacancies.retrieve(vacancy_id, params, headers)
16
+ res
17
+ end
18
+
19
+ def refresh(params={}, headers={})
20
+ res = client.vacancies.retrieve(id, params, headers)
21
+ self.refresh_from(res.json, res.api_method, res.client)
22
+ end
23
+
24
+ def delete(params={}, headers={})
25
+ res = client.vacancies.delete(id, params, headers)
26
+ self.refresh_from(res.json, res.api_method, res.client)
27
+ end
28
+
29
+ def bookings()
30
+ VacancyBookingsEndpoint.new(client, self)
31
+ end
32
+
33
+ # Everything below here is used behind the scenes.
34
+ ApiResource.register_api_subclass(self, "vacancy")
35
+ @api_attributes = {
36
+ :created_at => {},
37
+ :created_at_rfc822 => {},
38
+ :end_at => {},
39
+ :end_at_rfc822 => {},
40
+ :id => {},
41
+ :object => {},
42
+ :start_at => {},
43
+ :start_at_rfc822 => {},
44
+ :updated_at => {},
45
+ :updated_at_rfc822 => {},
46
+ }
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module Alman
2
+ VERSION = File.open(File.expand_path("../../../VERSION", __FILE__)).read()
3
+ end