timekit 0.1.0

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.
@@ -0,0 +1,94 @@
1
+ module Timekit
2
+ class Event
3
+ # Client class for the event resource
4
+ class Client < Timekit::Client
5
+ API_PATH = '/events'.freeze
6
+
7
+ def list(start_datetime, end_datetime)
8
+ params = {
9
+ start: start_datetime,
10
+ end: end_datetime
11
+ }
12
+
13
+ get(API_PATH, params)
14
+ end
15
+
16
+ def show(id)
17
+ get(API_PATH + '/' + id.to_s)
18
+ end
19
+
20
+ def create(
21
+ event_start,
22
+ event_end,
23
+ what,
24
+ where,
25
+ calendar_id,
26
+ participants = nil,
27
+ invite = nil,
28
+ description = nil,
29
+ sync_provider = nil,
30
+ my_rsvp = nil,
31
+ all_day = nil
32
+ )
33
+
34
+ params = {
35
+ start: event_start,
36
+ end: event_end,
37
+ what: what,
38
+ where: where,
39
+ calendar_id: calendar_id
40
+ }
41
+
42
+ optional_params = [
43
+ :participants,
44
+ :invite,
45
+ :description,
46
+ :my_rsvp,
47
+ :sync_provider,
48
+ :all_day
49
+ ]
50
+
51
+ optional_params.each do |name|
52
+ value = binding.local_variable_get(name)
53
+ params[name.to_sym] = value if [true, false].include?(value) ||
54
+ !value.nil?
55
+ end
56
+
57
+ post(API_PATH, params)
58
+ end
59
+
60
+ def update(
61
+ id,
62
+ event_start = nil,
63
+ event_end = nil,
64
+ what = nil,
65
+ where = nil,
66
+ participants = nil,
67
+ all_day = nil
68
+ )
69
+ params = {}
70
+ params[:start] = event_start if event_start
71
+ params[:end] = event_end if event_end
72
+
73
+ optional_params = [
74
+ :what,
75
+ :where,
76
+ :participants,
77
+ :all_day
78
+ ]
79
+
80
+ optional_params.each do |name|
81
+ value = binding.local_variable_get(name)
82
+ params[name.to_sym] = value if
83
+ [true, false].include?(value) || !value.nil?
84
+ end
85
+
86
+ put(API_PATH + '/' + id.to_s, params)
87
+ end
88
+
89
+ def delete(id)
90
+ super(API_PATH + '/' + id.to_s)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './event/client'
2
+
3
+ module Timekit
4
+ class Event
5
+ end
6
+ end
@@ -0,0 +1,87 @@
1
+ module Timekit
2
+ class Filtercollection
3
+ DAYS = %w(
4
+ Monday
5
+ Tuesday
6
+ Wednesday
7
+ Thursday
8
+ Friday
9
+ Saturday
10
+ Sunday
11
+ ).freeze
12
+
13
+ def initialize
14
+ @and_conditions = []
15
+ @or_conditions = []
16
+ @after_conditions = []
17
+ end
18
+
19
+ def as_json
20
+ {
21
+ or: @or_conditions,
22
+ and: @and_conditions,
23
+ after: @after_conditions
24
+ }
25
+ end
26
+
27
+ def after_take_random(num)
28
+ @after_conditions << { take_random: { number: num } }
29
+ end
30
+
31
+ def after_take_first(num)
32
+ @after_conditions << { take_first: { number: num } }
33
+ end
34
+
35
+ def after_take_last(num)
36
+ @after_conditions << { take_last: { number: num } }
37
+ end
38
+
39
+ def and_only_during_business_hours(timezone = nil)
40
+ @and_conditions << { business_hours: timezone_param(timezone) }
41
+ end
42
+
43
+ def and_not_on_weekends(timezone = nil)
44
+ @and_conditions << { exclude_weekends: timezone_param(timezone) }
45
+ end
46
+
47
+ def and_on_day(day)
48
+ @and_conditions << specific_day(day)
49
+ end
50
+
51
+ def or_on_any_days(days)
52
+ days.each { |day| @or_conditions << specific_day(day) }
53
+ end
54
+
55
+ def or_between_times(timestamp1, timestamp2)
56
+ @or_conditions << {
57
+ between_timestamps: {
58
+ start: timestamp1,
59
+ end: timestamp2
60
+ }
61
+ }
62
+ end
63
+
64
+ private
65
+
66
+ def timezone_param(timezone)
67
+ timezone ? { timezone: timezone } : {}
68
+ end
69
+
70
+ def specific_day(day)
71
+ raise "Invalid day #{day}" unless DAYS.include?(day)
72
+ { specific_day: { day: day } }
73
+ end
74
+
75
+ # def specific_day_and_time(day, start_time, end_time, timezone)
76
+ # raise "Invalid day #{day}" unless DAYS.include?(day)
77
+ #
78
+ # {
79
+ # specific_day_and_time: {
80
+ # day: day,
81
+ # start: start_time,
82
+ # end: end_time
83
+ # }.merge!(timezone_param(timezone))
84
+ # }
85
+ # end
86
+ end
87
+ end
@@ -0,0 +1,41 @@
1
+ module Timekit
2
+ class Findtime
3
+ # Client class for the findtime resource
4
+ class Client < Timekit::Client
5
+ API_PATH = '/findtime'.freeze
6
+
7
+ def query(
8
+ emails = nil,
9
+ user_ids = nil,
10
+ calendar_ids = nil,
11
+ filters = {},
12
+ filtercollection_id = nil,
13
+ start = nil,
14
+ future = '2 days',
15
+ length = '1 hour',
16
+ sort = 'asc',
17
+ ignore_all_day_events = false,
18
+ all_solutions = false
19
+ )
20
+ params = {}
21
+
22
+ # All args are optional, so we can examine each arg and
23
+ # set it as a key in the params hash if a value exists for the arg
24
+ method(__method__).parameters.map do |_, name|
25
+ value = binding.local_variable_get(name)
26
+ params[name.to_sym] = value if [true, false].include?(value) ||
27
+ !value.nil?
28
+ end
29
+
30
+ raise 'Entity id required to find time'\
31
+ ' (email,user id,calendar id)' unless
32
+ params[:emails] || params[:user_ids] || params[:calendar_ids]
33
+
34
+ post(API_PATH, params)
35
+ end
36
+
37
+ def bulk_query(queries)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ module Timekit
2
+ class Findtime
3
+ class Filtercollections
4
+ # Client class for the filtercollection resource
5
+ class Client < Timekit::Client
6
+ API_PATH = '/findtime/filtercollections'.freeze
7
+
8
+ def create(
9
+ and_conditions = nil,
10
+ or_conditions = nil,
11
+ after_conditions = nil
12
+ )
13
+ params = {
14
+ and: and_conditions,
15
+ or: or_conditions,
16
+ after: after_conditions
17
+ }
18
+
19
+ post(API_PATH, params)
20
+ end
21
+
22
+ def show(id)
23
+ get(API_PATH + '/' + id.to_s)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './findtime/client'
2
+
3
+ module Timekit
4
+ class Findtime
5
+ end
6
+ end
@@ -0,0 +1,39 @@
1
+ require 'singleton'
2
+ require 'rest-client'
3
+
4
+ module Timekit
5
+ # class for executing http requests against timekit api
6
+ class Request
7
+ include Singleton
8
+
9
+ BASE_URL = 'https://api.timekit.io/v2'.freeze
10
+
11
+ [:get, :put, :post, :delete].each do |verb|
12
+ define_method(verb) do |path, params, headers|
13
+ request __method__, path, params, headers
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def request(verb, path, params, headers)
20
+ headers = headers.merge!(http_headers)
21
+
22
+ # puts "Timekit::Request::request #{verb},"\
23
+ # " #{BASE_URL}#{path}, #{params}, #{headers}"
24
+ RestClient::Request.execute(
25
+ method: verb.downcase.to_sym,
26
+ url: "#{BASE_URL}#{path}",
27
+ payload: params ? params.to_json : nil,
28
+ headers: headers
29
+ )
30
+ end
31
+
32
+ def http_headers
33
+ {
34
+ content_type: 'application/json',
35
+ accept: 'application/json'
36
+ }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ module Timekit
2
+ class User
3
+ # Client class for the user resource
4
+ class Client < Timekit::Client
5
+ API_PATH = '/users'.freeze
6
+
7
+ def me
8
+ get(API_PATH + '/me')
9
+ end
10
+
11
+ def timezone(email)
12
+ get(API_PATH + '/timezone/' + email)
13
+ end
14
+
15
+ def update(
16
+ first_name = nil,
17
+ last_name = nil,
18
+ timezone = nil,
19
+ password = nil
20
+ )
21
+ params = {}
22
+
23
+ params[:first_name] = first_name if first_name
24
+ params[:last_name] = last_name if last_name
25
+ params[:timezone] = timezone if timezone
26
+ params[:password] = password if password
27
+
28
+ put(API_PATH + '/me', params)
29
+ end
30
+
31
+ def reset_password(email)
32
+ params = {
33
+ email: email
34
+ }
35
+
36
+ post(API_PATH + '/resetpassword', params)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ require_relative './user/client'
2
+
3
+ module Timekit
4
+ # this class is used for User creation
5
+ class User
6
+ # this hits a public endpoint, no authorization required
7
+ def self.create(
8
+ email,
9
+ timezone,
10
+ first_name,
11
+ last_name = nil,
12
+ password = nil
13
+ )
14
+
15
+ params = {
16
+ email: email,
17
+ timezone: timezone,
18
+ first_name: first_name
19
+ }
20
+ params[:last_name] = last_name if last_name
21
+ params[:password] = password if password
22
+
23
+ Timekit::Request.instance.send(
24
+ :post,
25
+ "#{Timekit.config[:api_endpoint]}#{Timekit::User::Client::API_PATH}",
26
+ params,
27
+ 'Timekit-App' => Timekit.config[:app]
28
+ )
29
+ end
30
+
31
+ def self.auth(email, password)
32
+ params = {
33
+ email: email,
34
+ password: password
35
+ }
36
+
37
+ Timekit::Request.instance.send(
38
+ :post,
39
+ "#{Timekit.config[:api_endpoint]}/auth",
40
+ params,
41
+ 'Timekit-App' => Timekit.config[:app]
42
+ )
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module Timekit
2
+ module Version
3
+ module_function
4
+
5
+ # @return [Integer]
6
+ def major
7
+ 0
8
+ end
9
+
10
+ # @return [Integer]
11
+ def minor
12
+ 1
13
+ end
14
+
15
+ # @return [Integer]
16
+ def patch
17
+ 0
18
+ end
19
+
20
+ # @return [Integer, NilClass]
21
+ def pre
22
+ nil
23
+ end
24
+
25
+ # @return [Hash]
26
+ def to_h
27
+ {
28
+ major: major,
29
+ minor: minor,
30
+ patch: patch,
31
+ pre: pre
32
+ }
33
+ end
34
+
35
+ # @return [Array]
36
+ def to_a
37
+ [major, minor, patch, pre].compact
38
+ end
39
+
40
+ # @return [String]
41
+ def to_s
42
+ to_a.join('.')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,54 @@
1
+ module Timekit
2
+ class Widget
3
+ # Client class for the widget resource
4
+ class Client < Timekit::Client
5
+ API_PATH = '/widgets'.freeze
6
+
7
+ def list
8
+ get(API_PATH)
9
+ end
10
+
11
+ def embed(id)
12
+ get(API_PATH + '/embed/' + id.to_s)
13
+ end
14
+
15
+ def hosted(slug)
16
+ get(API_PATH + '/hosted/' + slug)
17
+ end
18
+
19
+ def update(
20
+ id,
21
+ config,
22
+ name = nil,
23
+ slug = nil
24
+ )
25
+ params = {
26
+ config: config
27
+ }
28
+
29
+ params[:name] = name if name
30
+ params[:slug] = slug if slug
31
+
32
+ put(API_PATH + '/' + id.to_s, params)
33
+ end
34
+
35
+ def create(
36
+ config,
37
+ name,
38
+ slug
39
+ )
40
+ params = {
41
+ config: config,
42
+ name: name,
43
+ slug: slug
44
+ }
45
+
46
+ post(API_PATH, params)
47
+ end
48
+
49
+ def delete(id)
50
+ super(API_PATH + '/' + id.to_s)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+ require_relative './widget/client'
2
+
3
+ module Timekit
4
+ class Widget
5
+ end
6
+ end
data/lib/timekit.rb ADDED
@@ -0,0 +1,65 @@
1
+ require_relative './timekit/config'
2
+ require_relative './timekit/client'
3
+ require_relative './timekit/authorization'
4
+ require_relative './timekit/user'
5
+ require_relative './timekit/credential'
6
+ require_relative './timekit/app'
7
+ require_relative './timekit/calendar'
8
+ require_relative './timekit/event'
9
+ require_relative './timekit/request'
10
+ require_relative './timekit/findtime'
11
+ require_relative './timekit/filtercollection'
12
+ require_relative './timekit/widget'
13
+ require_relative './timekit/booking'
14
+
15
+ # Timekit class is responsible for handling configurations
16
+ # and provides helpers for instantiating clients for apis
17
+ module Timekit
18
+ @config = Timekit::Config.new
19
+
20
+ def self.config
21
+ @config
22
+ end
23
+
24
+ def self.configure(configurations)
25
+ config[:app] = configurations[:app] if configurations[:app]
26
+
27
+ email = configurations[:email]
28
+ token = configurations[:api_token]
29
+ config[:credentials] = Timekit::Authorization.new(
30
+ email, token
31
+ ) if email && token
32
+ end
33
+
34
+ def self.calendar_client
35
+ Timekit::Calendar::Client.new(config[:app], config[:credentials])
36
+ end
37
+
38
+ def self.app_client
39
+ Timekit::App::Client.new(config[:app], config[:credentials])
40
+ end
41
+
42
+ def self.credential_client
43
+ Timekit::Credential::Client.new(config[:app], config[:credentials])
44
+ end
45
+
46
+ def self.event_client
47
+ Timekit::Event::Client.new(config[:app], config[:credentials])
48
+ end
49
+
50
+ def self.user_client
51
+ Timekit::User::Client.new(config[:app], config[:credentials])
52
+ end
53
+
54
+ def self.findtime_client
55
+ Timekit::Findtime::Client.new(config[:app], config[:credentials])
56
+ end
57
+
58
+ def self.widget_client
59
+ Timekit::Widget::Client.new(config[:app], config[:credentials])
60
+ end
61
+
62
+ def self.booking_client
63
+ Timekit::Booking::Client.new(config[:app], config[:credentials])
64
+ end
65
+ end
data/timekit.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'timekit/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.add_dependency 'rest-client', '~> 1.6'
7
+ s.name = 'timekit'
8
+ s.version = '0.1.0'
9
+ s.date = '2016-06-02'
10
+ s.description = 'A gem to interact with the timekit.io api'
11
+ s.summary = s.description
12
+ s.authors = ['Michael Gauthier']
13
+ s.email = 'michael.gauthier@gmail.com'
14
+ s.files = ['lib/timekit.rb']
15
+ s.homepage = 'http://rubygems.org/gems/timekit'
16
+ s.license = 'MIT'
17
+ s.require_paths = %w(lib)
18
+ s.files = %w(
19
+ CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md timekit.gemspec
20
+ ) + Dir['lib/**/*.rb']
21
+ s.version = Timekit::Version
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timekit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Gauthier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-02 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.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ description: A gem to interact with the timekit.io api
28
+ email: michael.gauthier@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - CONTRIBUTING.md
35
+ - LICENSE.md
36
+ - README.md
37
+ - lib/timekit.rb
38
+ - lib/timekit/app.rb
39
+ - lib/timekit/app/client.rb
40
+ - lib/timekit/authorization.rb
41
+ - lib/timekit/booking.rb
42
+ - lib/timekit/booking/client.rb
43
+ - lib/timekit/calendar.rb
44
+ - lib/timekit/calendar/client.rb
45
+ - lib/timekit/client.rb
46
+ - lib/timekit/config.rb
47
+ - lib/timekit/credential.rb
48
+ - lib/timekit/credential/client.rb
49
+ - lib/timekit/event.rb
50
+ - lib/timekit/event/client.rb
51
+ - lib/timekit/filtercollection.rb
52
+ - lib/timekit/findtime.rb
53
+ - lib/timekit/findtime/client.rb
54
+ - lib/timekit/findtime/filtercollections/client.rb
55
+ - lib/timekit/request.rb
56
+ - lib/timekit/user.rb
57
+ - lib/timekit/user/client.rb
58
+ - lib/timekit/version.rb
59
+ - lib/timekit/widget.rb
60
+ - lib/timekit/widget/client.rb
61
+ - timekit.gemspec
62
+ homepage: http://rubygems.org/gems/timekit
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.5.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A gem to interact with the timekit.io api
86
+ test_files: []
87
+ has_rdoc: