youcanbookme-api-ruby 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f4b96e82ba806c92ad7aa1b97bcbea9d5528f1c
4
+ data.tar.gz: 459350f9d7bf92b9f1aefbfbb04c398ff8dc82b9
5
+ SHA512:
6
+ metadata.gz: 915abb3b5035123dc4a42b9a35f4d8ff81d2e2e02b567f80f8b576c7f3d6a7c67a23cb9c85854cffee131cb13fb17fa3089e35663ad4dc20e26fe3023f14d174
7
+ data.tar.gz: a790149debf55dc27a777b228ef74803b1cca7647b7cf7d0163ad663d4ef92acf3af02023c25e924846e17958a4c15800e21d85f6cd9ae6706df659fb953916b
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in YouCanBookMe-API-Ruby.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'rspec', '~> 3.0'
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ youcanbookme-api-ruby (0.0.3)
5
+ http (~> 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.7.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.0)
13
+ diff-lcs (1.3)
14
+ domain_name (0.5.20190701)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ ffi (1.12.2)
17
+ ffi-compiler (1.0.1)
18
+ ffi (>= 1.0.0)
19
+ rake
20
+ http (4.3.0)
21
+ addressable (~> 2.3)
22
+ http-cookie (~> 1.0)
23
+ http-form_data (~> 2.2)
24
+ http-parser (~> 1.2.0)
25
+ http-cookie (1.0.3)
26
+ domain_name (~> 0.5)
27
+ http-form_data (2.2.0)
28
+ http-parser (1.2.1)
29
+ ffi-compiler (>= 1.0, < 2.0)
30
+ jaro_winkler (1.5.4)
31
+ parallel (1.19.1)
32
+ parser (2.7.0.2)
33
+ ast (~> 2.4.0)
34
+ powerpack (0.1.2)
35
+ public_suffix (4.0.3)
36
+ rainbow (3.0.0)
37
+ rake (12.3.3)
38
+ rspec (3.9.0)
39
+ rspec-core (~> 3.9.0)
40
+ rspec-expectations (~> 3.9.0)
41
+ rspec-mocks (~> 3.9.0)
42
+ rspec-core (3.9.1)
43
+ rspec-support (~> 3.9.1)
44
+ rspec-expectations (3.9.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-mocks (3.9.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.9.0)
50
+ rspec-support (3.9.2)
51
+ rubocop (0.62.0)
52
+ jaro_winkler (~> 1.5.1)
53
+ parallel (~> 1.10)
54
+ parser (>= 2.5, != 2.5.1.1)
55
+ powerpack (~> 0.1)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (~> 1.4.0)
59
+ ruby-progressbar (1.10.1)
60
+ unf (0.1.4)
61
+ unf_ext
62
+ unf_ext (0.0.7.6)
63
+ unicode-display_width (1.4.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 2.1.4)
70
+ rake (~> 12.0)
71
+ rspec (~> 3.0)
72
+ rubocop (~> 0.62.0)
73
+ youcanbookme-api-ruby!
74
+
75
+ BUNDLED WITH
76
+ 2.1.4
@@ -0,0 +1 @@
1
+ # YouCanBookMe-API-Ruby
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'YouCanBookMe/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'youcanbookme-api-ruby'
9
+ spec.version = YouCanBookMe::VERSION
10
+ spec.authors = ['ma3tk']
11
+ spec.email = ['masataka0227@gmail.com']
12
+
13
+ spec.summary = 'YouCanBook.Me API Wrapper'
14
+ spec.description = 'YouCanBook.Me API Wrapper'
15
+ spec.homepage = 'https://github.com/ma3tk/YouCanBookMe-API-Ruby'
16
+ spec.license = 'MIT'
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ spec.metadata['source_code_uri'] = 'https://github.com/ma3tk/YouCanBookMe-API-Ruby'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/ma3tk/YouCanBookMe-API-Ruby'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'http', '~> 4.0'
34
+ spec.add_development_dependency 'bundler', '~> 2.1.4'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rubocop', '~> 0.62.0'
38
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'youcanbookme'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YouCanBookMe/client/profiles'
4
+ require 'YouCanBookMe/client/bookings'
5
+
6
+ module YouCanBookMe
7
+ class Client
8
+ include YouCanBookMe::Client::Profiles
9
+ include YouCanBookMe::Client::Bookings
10
+
11
+ def initialize(options = {})
12
+ email = options[:email] || ENV['YOUCANBOOKME_EMAIL']
13
+ password = options[:password] || ENV['YOUCANBOOKME_PASSWORD']
14
+
15
+ raise YouCanBookMe::AuthorizationNotSpecified if email.empty? || password.empty?
16
+
17
+ YouCanBookMe.instance_variable_set(:@email, email)
18
+ YouCanBookMe.instance_variable_set(:@password, password)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YouCanBookMe/connection'
4
+
5
+ module YouCanBookMe
6
+ class Client
7
+ module Account
8
+ include YouCanBookMe::Connection::API
9
+
10
+ def show(params = {})
11
+ get('', params)
12
+ end
13
+
14
+ def update(params = {})
15
+ patch('', params)
16
+ end
17
+
18
+ def destroy(params = {})
19
+ delete('', params)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YouCanBookMe/connection'
4
+
5
+ module YouCanBookMe
6
+ class Client
7
+ module Bookings
8
+ include YouCanBookMe::Connection::API
9
+
10
+ def index(params = {})
11
+ get('/bookings', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YouCanBookMe/connection'
4
+
5
+ module YouCanBookMe
6
+ class Client
7
+ module Caligraph
8
+ include YouCanBookMe::Connection::Caligraph
9
+
10
+ def api_key
11
+ params = {
12
+ fields: 'apiKey'
13
+ }
14
+ get('/', params).parse['apiKey']
15
+ end
16
+
17
+ def set_api_key
18
+ YouCanBookMe.instance_variable_set(:@password, api_key)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YouCanBookMe
4
+ class Error < StandardError
5
+ class << self
6
+ def raise_from(response)
7
+ status = response.code
8
+ return if (200..299).cover?(status)
9
+
10
+ klass = case status
11
+ when 400 then YouCanBookMe::BadRequest
12
+ when 400..499 then YouCanBookMe::ClientError
13
+ when 500 then YouCanBookMe::InternalServerError
14
+ when 500..599 then YouCanBookMe::ServerError
15
+ else YouCanBookMe::UnknownError
16
+ end
17
+ # FIXME
18
+ raise klass, response.code
19
+ end
20
+ end
21
+ end
22
+
23
+ class AuthorizationNotSpecified < Error; end
24
+ class ClientError < Error; end
25
+ class BadRequest < ClientError; end
26
+ class ServerError < Error; end
27
+ class InternalServerError < ServerError; end
28
+ class UnknownError < Error; end
29
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YouCanBookMe/connection'
4
+
5
+ module YouCanBookMe
6
+ class Client
7
+ module Profiles
8
+ include YouCanBookMe::Connection::API
9
+
10
+ def index(params = {})
11
+ get('/profiles', params)
12
+ end
13
+
14
+ def create(params = {})
15
+ post('/profiles', params)
16
+ end
17
+
18
+ def show(profile_id, params = {})
19
+ get("/profiles/#{profile_id}", params)
20
+ end
21
+
22
+ def update(profile_id, params = {})
23
+ patch("/profiles/#{profile_id}", params)
24
+ end
25
+
26
+ def destroy(profile_id, params = {})
27
+ delete("/profiles/#{profile_id}", params)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YouCanBookMe/connection'
4
+
5
+ module YouCanBookMe
6
+ class Client
7
+ module Profiles
8
+ module Bookings
9
+ include YouCanBookMe::Connection::API
10
+
11
+ def index(profile_id, params = {})
12
+ get("/profiles/#{profile_id}/bookings", params)
13
+ end
14
+
15
+ def create(profile_id, params = {})
16
+ post("/profiles/#{profile_id}/bookings", params)
17
+ end
18
+
19
+ def show(profile_id, booking_id, params = {})
20
+ get("/profiles/#{profile_id}/bookings/#{booking_id}", params)
21
+ end
22
+
23
+ def update(profile_id, booking_id, params = {})
24
+ patch("/profiles/#{profile_id}/bookings/#{booking_id}", params)
25
+ end
26
+
27
+ def destroy(profile_id, booking_id, params = {})
28
+ delete("/profiles/#{profile_id}/bookings/#{booking_id}", params)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'YouCanBookMe/Client/Error'
5
+ require 'YouCanBookMe'
6
+ require 'YouCanBookMe/Connection/API'
7
+
8
+ module YouCanBookMe
9
+ module Connection
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'YouCanBookMe/Client/Error'
5
+ require 'YouCanBookMe'
6
+
7
+ module YouCanBookMe
8
+ module Connection
9
+ module API
10
+ BASE_URL = 'https://api.youcanbook.me/v1/'.freeze
11
+
12
+ protected
13
+
14
+ def get(path, data)
15
+ email = YouCanBookMe.instance_variable_get(:@email)
16
+ password = YouCanBookMe.instance_variable_get(:@password)
17
+ response = HTTP.basic_auth(user: email, pass: password).get(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, params: data)
18
+ YouCanBookMe::Error.raise_from(response)
19
+ response.parse
20
+ end
21
+
22
+ def post(path, data)
23
+ email = YouCanBookMe.instance_variable_get(:@email)
24
+ password = YouCanBookMe.instance_variable_get(:@password)
25
+ response = HTTP.basic_auth(user: email, pass: password).post(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, json: data)
26
+ YouCanBookMe::Error.raise_from(response)
27
+ response.parse
28
+ end
29
+
30
+ def put(path, data)
31
+ email = YouCanBookMe.instance_variable_get(:@email)
32
+ password = YouCanBookMe.instance_variable_get(:@password)
33
+ response = HTTP.basic_auth(user: email, pass: password).put(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, json: data)
34
+ YouCanBookMe::Error.raise_from(response)
35
+ response.parse
36
+ end
37
+
38
+ def delete(path, data)
39
+ email = YouCanBookMe.instance_variable_get(:@email)
40
+ password = YouCanBookMe.instance_variable_get(:@password)
41
+ response = HTTP.basic_auth(user: email, pass: password).delete(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, json: data)
42
+ YouCanBookMe::Error.raise_from(response)
43
+ response.parse
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+ require 'YouCanBookMe/Client/Error'
5
+ require 'YouCanBookMe'
6
+
7
+ module YouCanBookMe
8
+ module Connection
9
+ module Caligraph
10
+ BASE_URL = 'https://caligraph.youcanbook.me/v1/'.freeze
11
+
12
+ protected
13
+
14
+ def get(path, data)
15
+ email = YouCanBookMe.instance_variable_get(:@email)
16
+ password = YouCanBookMe.instance_variable_get(:@password)
17
+ response = HTTP.basic_auth(user: email, pass: password).get(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, params: data)
18
+ YouCanBookMe::Error.raise_from(response)
19
+ response.parse
20
+ end
21
+
22
+ def post(path, data)
23
+ email = YouCanBookMe.instance_variable_get(:@email)
24
+ password = YouCanBookMe.instance_variable_get(:@password)
25
+ response = HTTP.basic_auth(user: email, pass: password).post(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, json: data)
26
+ YouCanBookMe::Error.raise_from(response)
27
+ response.parse
28
+ end
29
+
30
+ def put(path, data)
31
+ email = YouCanBookMe.instance_variable_get(:@email)
32
+ password = YouCanBookMe.instance_variable_get(:@password)
33
+ response = HTTP.basic_auth(user: email, pass: password).put(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, json: data)
34
+ YouCanBookMe::Error.raise_from(response)
35
+ response.parse
36
+ end
37
+
38
+ def delete(path, data)
39
+ email = YouCanBookMe.instance_variable_get(:@email)
40
+ password = YouCanBookMe.instance_variable_get(:@password)
41
+ response = HTTP.basic_auth(user: email, pass: password).delete(Addressable::URI.parse(BASE_URL + email + path.to_s).normalize.to_s, json: data)
42
+ YouCanBookMe::Error.raise_from(response)
43
+ response.parse
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module YouCanBookMe
2
+ VERSION = '0.0.3'.freeze
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'YouCanBookMe/version'
2
+ require 'YouCanBookMe/client'
3
+
4
+ module YouCanBookMe
5
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: youcanbookme-api-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - ma3tk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.62.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.62.0
83
+ description: YouCanBook.Me API Wrapper
84
+ email:
85
+ - masataka0227@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - README.md
93
+ - Rakefile
94
+ - YouCanBookMe-API-Ruby.gemspec
95
+ - bin/console
96
+ - bin/setup
97
+ - lib/YouCanBookMe/client.rb
98
+ - lib/YouCanBookMe/client/account.rb
99
+ - lib/YouCanBookMe/client/bookings.rb
100
+ - lib/YouCanBookMe/client/caligraph.rb
101
+ - lib/YouCanBookMe/client/error.rb
102
+ - lib/YouCanBookMe/client/profiles.rb
103
+ - lib/YouCanBookMe/client/profiles/bookings.rb
104
+ - lib/YouCanBookMe/connection.rb
105
+ - lib/YouCanBookMe/connection/api.rb
106
+ - lib/YouCanBookMe/connection/caligraph.rb
107
+ - lib/YouCanBookMe/version.rb
108
+ - lib/youcanbookme.rb
109
+ homepage: https://github.com/ma3tk/YouCanBookMe-API-Ruby
110
+ licenses:
111
+ - MIT
112
+ metadata:
113
+ homepage_uri: https://github.com/ma3tk/YouCanBookMe-API-Ruby
114
+ allowed_push_host: https://rubygems.org
115
+ source_code_uri: https://github.com/ma3tk/YouCanBookMe-API-Ruby
116
+ changelog_uri: https://github.com/ma3tk/YouCanBookMe-API-Ruby
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: 2.3.0
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.6.13
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: YouCanBook.Me API Wrapper
137
+ test_files: []