bookafy 0.1.5

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e79247bfc577518a6f5dc209a7eede9821873d6e
4
+ data.tar.gz: c94c4f0f675bed22dd80cc22e7e722ce7d913c38
5
+ SHA512:
6
+ metadata.gz: 919c151342cc33101f955fb55d4dbb7af96fea306c8816e511d668ab972f4295de446a8458d5367e155e55dacb14c27400b85aa79d23feafdf46f17ec9596b2f
7
+ data.tar.gz: f8c762a0fb12c5d8b63027c3cb8da4e2743f0938095002682db45f7e8dbcdb43b9c930f2289c54e8cdbd81c08cffa553219fb2f9fba086f6be19279725eb4499
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at bajalovic@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bookafy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ivan Bajalovic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Bookafy::Rails
2
+
3
+ This is a gem that enables you to get customer and appointment data from [Bookafy](http://www.bookafy.com/).
4
+
5
+ Bookafy is an automated scheduling for service appointments, calls, meetings, and much more.
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/bookafy.svg)](https://badge.fury.io/rb/bookafy)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'bookafy'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install bookafy
24
+
25
+ ## Usage
26
+
27
+ Once you obtain OAuth access token, you should set it up
28
+
29
+ ```rails
30
+ Bookafy.access_token = '6911d4a6b217bd637db0c81741482cdb497738cd52c1b3996528094c1e47c345'
31
+ ```
32
+
33
+ #### Customers
34
+
35
+ To fetch all customers you can use:
36
+
37
+ ```rails
38
+ customer_service = Bookafy::Customer.new
39
+ customers = customer_service.all # an array of Customer models
40
+
41
+ # or if you want to get only customers that have been updated since some time
42
+ customers = customer_service.all(updated: 7.days.ago.to_i)
43
+ ```
44
+
45
+ #### Appointments
46
+
47
+ To fetch all appointments you can use:
48
+
49
+ ```rails
50
+ appointments_service = Bookafy::Appointment.new
51
+ appointments = appointments_service.all # an array of Appointment models
52
+
53
+ # or if you want to get only customers that have been updated since some time
54
+ appointments = appointments_service.all(updated: 7.days.ago.to_i)
55
+ ```
56
+
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bookafy-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
61
+
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
66
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bookafy/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -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
data/bookafy.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bookafy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bookafy"
8
+ spec.version = Bookafy::VERSION
9
+ spec.authors = ["Ivan Bajalovic"]
10
+ spec.email = ["bajalovic@gmail.com"]
11
+
12
+ spec.summary = %q{Get data from Bookafy}
13
+ spec.description = %q{Used to sync data from Bookafy}
14
+ spec.homepage = "https://github.com/crankapps/bookafy-rails"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+
34
+ spec.add_development_dependency "railties"
35
+ spec.add_development_dependency "httparty"
36
+ spec.add_development_dependency "test-unit", "1.2.3"
37
+ spec.add_development_dependency "activesupport"
38
+ spec.add_development_dependency "mocha"
39
+ spec.add_development_dependency "webmock"
40
+ end
data/lib/bookafy.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "bookafy/version"
2
+ require "bookafy/base_service"
3
+ require "bookafy/model/timestamps"
4
+ require "bookafy/model/customer"
5
+ require "bookafy/model/appointment"
6
+ require "bookafy/customer"
7
+ require "bookafy/appointment"
8
+
9
+ module Bookafy
10
+
11
+ @base_url = 'http://bookafydev.com'
12
+ @access_token = ''
13
+
14
+ class << self
15
+ attr_accessor :base_url
16
+ attr_accessor :access_token
17
+ end
18
+
19
+ end
@@ -0,0 +1,38 @@
1
+ module Bookafy
2
+ class Appointment < BaseService
3
+
4
+ def initialize
5
+ super
6
+ @page = 1
7
+ end
8
+
9
+ def uri
10
+ 'appointments'
11
+ end
12
+
13
+ def all(query_params = {})
14
+ query_params[:page] = @page
15
+ response = get(uri, query_params)
16
+ unless response.code == 200
17
+ return []
18
+ end
19
+
20
+ response_json = JSON.parse(response.body)['response']
21
+ appointments_json = response_json['appointments']
22
+ appointments = appointments_json.map do |data|
23
+ Bookafy::Model::Appointment.new(data)
24
+ end
25
+
26
+ if response_json['remaining'] > 0
27
+ @page = @page + 1
28
+ appointments += all(query_params)
29
+ end
30
+
31
+ appointments
32
+ rescue => e
33
+ puts "Error at fetching appointments: #{e.message}"
34
+ return []
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ require 'httparty'
2
+
3
+ module Bookafy
4
+ class BaseService
5
+ include HTTParty
6
+
7
+ API_VERSION = 'v1'
8
+
9
+ def initialize
10
+ url = Bookafy.base_url || 'http://bookafydev.com'
11
+ @domain = "#{url}/api/#{API_VERSION}/"
12
+ @token = Bookafy.access_token
13
+ end
14
+
15
+ def bookafy_api_url
16
+ @domain
17
+ end
18
+
19
+ def access_token
20
+ @token
21
+ end
22
+
23
+ def get(url, options={})
24
+ default_options = {token: @token, page: 1}.merge(options)
25
+ api_url = "#{@domain}#{url}"
26
+ response = HTTParty.get(api_url, {query: default_options})
27
+ response
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,38 @@
1
+ module Bookafy
2
+ class Customer < BaseService
3
+
4
+ def initialize
5
+ super
6
+ @page = 1
7
+ end
8
+
9
+ def uri
10
+ 'customers'
11
+ end
12
+
13
+ def all(query_params = {})
14
+ query_params[:page] = @page
15
+ response = get(uri, query_params)
16
+ unless response.code == 200
17
+ return []
18
+ end
19
+
20
+ response_json = JSON.parse(response.body)['response']
21
+ customers_json = response_json['customers']
22
+ customers = customers_json.map do |data|
23
+ Bookafy::Model::Customer.new(data)
24
+ end
25
+
26
+ if response_json['remaining'] > 0
27
+ @page = @page + 1
28
+ customers += all(query_params)
29
+ end
30
+
31
+ customers
32
+ rescue => e
33
+ puts "Error at fetching customers: #{e.message}"
34
+ return []
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ module Bookafy
2
+ module Model
3
+ class Appointment
4
+ include Timestamps
5
+
6
+ attr_accessor :id, :client_id, :customer_id, :created_at, :updated_at, :appointment_start_time, :appointment_end_time, :all_day, :title, :description, :price, :duration, :recurring, :is_active, :is_blocker, :all_day_blocker, :soft_delete
7
+
8
+ def initialize(attrs = {})
9
+ attrs.each do |attr, val|
10
+ if respond_to?("#{attr}=")
11
+ send("#{attr}=", val)
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ def active?
18
+ is_active
19
+ end
20
+
21
+ def blocker?
22
+ is_blocker
23
+ end
24
+
25
+ def all_day?
26
+ all_day
27
+ end
28
+
29
+ def recurring?
30
+ recurring
31
+ end
32
+
33
+ def all_day_blocker?
34
+ all_day_blocker
35
+ end
36
+
37
+ def created_at
38
+ Time.parse(attributes[:created_at])
39
+ end
40
+
41
+ def updated_at
42
+ Time.parse(attributes[:updated_at])
43
+ end
44
+
45
+ def appointment_start_time
46
+ Time.parse(attributes[:appointment_start_time])
47
+ end
48
+
49
+ def appointment_end_time
50
+ Time.parse(attributes[:appointment_end_time])
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,23 @@
1
+ module Bookafy
2
+ module Model
3
+ class Customer
4
+ include Timestamps
5
+ attr_accessor :id, :client_id, :created_at, :updated_at, :email, :name, :soft_delete
6
+
7
+ def initialize(attrs = {})
8
+ attrs.each do |attr, val|
9
+ send("#{attr}=", val) if respond_to?("#{attr}=")
10
+ end
11
+ end
12
+
13
+
14
+ def created_at
15
+ Time.parse(attributes[:created_at])
16
+ end
17
+
18
+ def updated_at
19
+ Time.parse(attributes[:updated_at])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'active_support'
2
+ module Bookafy
3
+ module Model
4
+ module Timestamps
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def attributes
9
+ attrs = {
10
+ created_at: @created_at,
11
+ updated_at: @udpated_at
12
+ }
13
+ if @appointment_start_time
14
+ attrs[:appointment_start_time] = @appointment_start_time
15
+ end
16
+ if @appointment_end_time
17
+ attrs[:appointment_end_time] = @appointment_end_time
18
+ end
19
+
20
+ attrs
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Bookafy
2
+ VERSION = '0.1.5'
3
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bookafy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Bajalovic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-19 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: railties
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Used to sync data from Bookafy
140
+ email:
141
+ - bajalovic@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - CODE_OF_CONDUCT.md
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - bin/console
154
+ - bin/setup
155
+ - bookafy.gemspec
156
+ - lib/bookafy.rb
157
+ - lib/bookafy/appointment.rb
158
+ - lib/bookafy/base_service.rb
159
+ - lib/bookafy/customer.rb
160
+ - lib/bookafy/model/appointment.rb
161
+ - lib/bookafy/model/customer.rb
162
+ - lib/bookafy/model/timestamps.rb
163
+ - lib/bookafy/version.rb
164
+ homepage: https://github.com/crankapps/bookafy-rails
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.6.4
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Get data from Bookafy
188
+ test_files: []