dm3-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/dm3-api.rb +9 -0
- data/lib/dm3/api/connection.rb +35 -0
- data/lib/dm3/api/requests.rb +17 -0
- data/lib/dm3/api/requests/base.rb +62 -0
- data/lib/dm3/api/requests/booking_subjects.rb +7 -0
- data/lib/dm3/api/requests/bookings.rb +15 -0
- data/lib/dm3/api/requests/create_booking.rb +7 -0
- data/lib/dm3/api/requests/delete.rb +5 -0
- data/lib/dm3/api/requests/destroy_booking.rb +7 -0
- data/lib/dm3/api/requests/get.rb +5 -0
- data/lib/dm3/api/requests/post.rb +9 -0
- data/lib/dm3/api/requests/put.rb +9 -0
- data/lib/dm3/api/requests/update_booking.rb +7 -0
- data/lib/dm3/api/responses.rb +13 -0
- data/lib/dm3/api/responses/base.rb +14 -0
- data/lib/dm3/api/responses/booking_subjects.rb +2 -0
- data/lib/dm3/api/responses/bookings.rb +2 -0
- data/lib/dm3/api/responses/create_booking.rb +2 -0
- data/lib/dm3/api/responses/destroy_booking.rb +2 -0
- data/lib/dm3/api/responses/update_booking.rb +2 -0
- data/lib/dm3/api/version.rb +5 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecae70151a267b8d65b07b5cf3a220a915e0dc17
|
4
|
+
data.tar.gz: a9dd8c797dc70bedd8d2942efa2383aa57cde1a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a519dd767e77c404eb8b973f950cb898401f1f3775ecf4e5d2778975d14cf8aee3e2adfb76897904b56b0938b395ed919192293aae35d8dd4c2db831ad816e1
|
7
|
+
data.tar.gz: 17240bb99c07e9c9519b1a93a5b56661d4a75b1ae8152520436741224771d7f458593ab1e9d70924c9b8e816a1d85a5a2c4387f4097a3bb1a889eb34f246502e
|
data/lib/dm3-api.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class Dm3::Api::Connection
|
2
|
+
attr_reader :service_url, :token
|
3
|
+
|
4
|
+
def initialize(token, service_url)
|
5
|
+
@token = token
|
6
|
+
@service_url = service_url
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(method_name, *args, &block)
|
10
|
+
request_class = request_class_for_method(method_name)
|
11
|
+
if request_class
|
12
|
+
request_class.new(self, args.extract_options!).perform
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def use_ssl?
|
19
|
+
service_uri.scheme == 'https'
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def service_uri
|
25
|
+
@service_uri ||= URI(service_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def request_class_for_method(method_name)
|
29
|
+
begin
|
30
|
+
"Dm3::Api::Requests::#{method_name.to_s.camelize}".constantize
|
31
|
+
rescue NameError
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Dm3
|
2
|
+
module Api
|
3
|
+
module Requests
|
4
|
+
autoload :Base, 'dm3/api/requests/base'
|
5
|
+
|
6
|
+
autoload :BookingSubjects, 'dm3/api/requests/booking_subjects'
|
7
|
+
autoload :Bookings, 'dm3/api/requests/bookings'
|
8
|
+
autoload :CreateBooking, 'dm3/api/requests/create_booking'
|
9
|
+
autoload :Delete, 'dm3/api/requests/delete'
|
10
|
+
autoload :DestroyBooking, 'dm3/api/requests/destroy_booking'
|
11
|
+
autoload :Get, 'dm3/api/requests/get'
|
12
|
+
autoload :Post, 'dm3/api/requests/post'
|
13
|
+
autoload :Put, 'dm3/api/requests/put'
|
14
|
+
autoload :UpdateBooking, 'dm3/api/requests/update_booking'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Dm3::Api::Requests::Base
|
2
|
+
attr_reader :connection, :opts
|
3
|
+
|
4
|
+
delegate :token, :service_url, :requests, :use_ssl?, to: :connection
|
5
|
+
|
6
|
+
def initialize(connection, opts = {})
|
7
|
+
@connection = connection
|
8
|
+
@opts = opts
|
9
|
+
end
|
10
|
+
|
11
|
+
def http_class
|
12
|
+
"Net::HTTP::#{http_method.camelize}".constantize
|
13
|
+
end
|
14
|
+
|
15
|
+
def perform
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
def response
|
20
|
+
response_class.new(http_response)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def raw_body
|
26
|
+
body.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
def body
|
30
|
+
opts.fetch(:body, {})
|
31
|
+
end
|
32
|
+
|
33
|
+
def response_class
|
34
|
+
"Dm3::Api::Responses::#{self.class.name.demodulize}".constantize
|
35
|
+
end
|
36
|
+
|
37
|
+
def http_request
|
38
|
+
@http_request ||= begin
|
39
|
+
req = http_class.new(uri, {'Content-Type' => 'application/json'})
|
40
|
+
req.body = raw_body if body.present?
|
41
|
+
req
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def http_response
|
46
|
+
@http_response ||= Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl?, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
47
|
+
http.request(http_request)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def path
|
52
|
+
fail NotImplementedError
|
53
|
+
end
|
54
|
+
|
55
|
+
def uri
|
56
|
+
URI('%s%s%stoken=%s' % [service_url, path, join_character, token])
|
57
|
+
end
|
58
|
+
|
59
|
+
def join_character
|
60
|
+
path['?'] ? '&' : '?'
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Dm3::Api::Requests::Bookings < Dm3::Api::Requests::Get
|
2
|
+
private
|
3
|
+
|
4
|
+
def path
|
5
|
+
"/api/v1/manager/bookings?from=#{from}&to=#{to}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def from
|
9
|
+
opts[:from].presence || Date.today.prev_month.beginning_of_month.iso8601
|
10
|
+
end
|
11
|
+
|
12
|
+
def to
|
13
|
+
opts[:to].presence || (Date.today + 6.months).end_of_month.iso8601
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Dm3
|
2
|
+
module Api
|
3
|
+
module Responses
|
4
|
+
autoload :Base, 'dm3/api/responses/base'
|
5
|
+
|
6
|
+
autoload :BookingSubjects, 'dm3/api/responses/booking_subjects'
|
7
|
+
autoload :Bookings, 'dm3/api/responses/bookings'
|
8
|
+
autoload :CreateBooking, 'dm3/api/responses/create_booking'
|
9
|
+
autoload :DestroyBooking, 'dm3/api/responses/destroy_booking'
|
10
|
+
autoload :UpdateBooking, 'dm3/api/responses/update_booking'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Dm3::Api::Responses::Base
|
2
|
+
attr_reader :raw_response, :json, :hash, :dish
|
3
|
+
|
4
|
+
def initialize(raw_response)
|
5
|
+
@raw_response = raw_response
|
6
|
+
@json = raw_response.body
|
7
|
+
@hash = JSON.parse(json)
|
8
|
+
@dish = Dish(hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(*args, &block)
|
12
|
+
dish.public_send(args.first)
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm3-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- stevo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: DM3 Ruby API wrapper
|
14
|
+
email:
|
15
|
+
- blazejek@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/dm3-api.rb
|
21
|
+
- lib/dm3/api/connection.rb
|
22
|
+
- lib/dm3/api/requests.rb
|
23
|
+
- lib/dm3/api/requests/base.rb
|
24
|
+
- lib/dm3/api/requests/booking_subjects.rb
|
25
|
+
- lib/dm3/api/requests/bookings.rb
|
26
|
+
- lib/dm3/api/requests/create_booking.rb
|
27
|
+
- lib/dm3/api/requests/delete.rb
|
28
|
+
- lib/dm3/api/requests/destroy_booking.rb
|
29
|
+
- lib/dm3/api/requests/get.rb
|
30
|
+
- lib/dm3/api/requests/post.rb
|
31
|
+
- lib/dm3/api/requests/put.rb
|
32
|
+
- lib/dm3/api/requests/update_booking.rb
|
33
|
+
- lib/dm3/api/responses.rb
|
34
|
+
- lib/dm3/api/responses/base.rb
|
35
|
+
- lib/dm3/api/responses/booking_subjects.rb
|
36
|
+
- lib/dm3/api/responses/bookings.rb
|
37
|
+
- lib/dm3/api/responses/create_booking.rb
|
38
|
+
- lib/dm3/api/responses/destroy_booking.rb
|
39
|
+
- lib/dm3/api/responses/update_booking.rb
|
40
|
+
- lib/dm3/api/version.rb
|
41
|
+
homepage: https://github.com/Selleo/dm3-api
|
42
|
+
licenses: []
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project: "[none]"
|
60
|
+
rubygems_version: 2.2.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: DM3 Ruby API wrapper
|
64
|
+
test_files: []
|