timekit 0.2.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 686be7c574283d5c3ead736936e362444bd041da
4
- data.tar.gz: f67c7e5cf6cbe4920d01b27d0fde638a32fa6b33
3
+ metadata.gz: adacb23f2e944fce92cbd0f0e6a4a11f9dd76f5e
4
+ data.tar.gz: 3ddc3a70a9f030c443865c0eafb472a7c1b8e0de
5
5
  SHA512:
6
- metadata.gz: 9693d02ff8d8c8660a5dd41720535dba23f17b79ae997ee026600a45f1631b5814a9d4d0b90264fbee2bc6bf579f6b0bd824048cee8ed695214c73e21cafa807
7
- data.tar.gz: 947a7a1a97aa1080c9314f4b1f9fc240c81a4eea7fe9a31a9a37bf85d35868546084b93ec6f97c81f8c1cd1e8ec9b12ff73fd159253fed11cb69e14e358e2f9f
6
+ metadata.gz: 18b055f4976b428266267bbc1847af6cb892b66fe0d7b1aa3d40ccb46819fb93b4848a9a01537dc6e2b6e730848c1798d1187e7057631f21851cef44ac409bcf
7
+ data.tar.gz: 4b5cd189e68793806ae4746f59fe874f70da249d4e1906305a44e2ef85f223e65d3441cbdc7aea52bc5566bde68079d5a632907c3b6f12838944373103ba3c7a
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApiModel < ActiveRest::Base
4
+ # api url: 'example.com'
5
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ConcreteExampleModel < ApiModel
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class OtherModel < ActiveRest::Base
4
+ end
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rest-client'
4
+ require 'active_model'
5
+ # require 'activemodel/serializers/xml'
6
+ # TODO: include strong_parameters?
7
+
8
+ module ActiveRest
9
+ class Base
10
+ include ActiveModel::AttributeMethods
11
+ include ActiveModel::Serialization
12
+ include ActiveModel::Serializers::JSON
13
+ # include ActiveModel::Serializers::Xml
14
+
15
+ def attributes=(hash)
16
+ hash.each do |key, value|
17
+ send("#{key}=", value)
18
+ end
19
+ end
20
+
21
+ def attributes
22
+ @attributes.to_hash
23
+ end
24
+
25
+ # def attributes
26
+ # {'name' => nil}
27
+ # end
28
+
29
+ def self.api(configurations)
30
+ configurations.each do |key, value|
31
+ define_singleton_method("api_#{key}") { nil }
32
+ singleton_class.class_eval do
33
+ remove_method("api_#{key}") if method_defined?("api_#{key}")
34
+ define_method("api_#{key}") { value }
35
+ end
36
+ end
37
+ end
38
+
39
+ # method GET
40
+ def self.all
41
+ puts name.to_s + ' .all'
42
+ # get
43
+ end
44
+
45
+ # method GET
46
+ def self.find(id)
47
+ puts name.to_s + ' .find ' + id
48
+ # get("/#{id}")
49
+ end
50
+
51
+ # method POST
52
+ def self.create(attrs = {})
53
+ puts name.to_s + ' .create ' + attrs.inspect
54
+ end
55
+
56
+ # serialize the attrs and PUT
57
+ # method PUT
58
+ def update(attrs = {})
59
+ puts name.to_s + ' .update ' + attrs.inspect
60
+ resp = self.class.request(:put, "/#{id}", attrs)
61
+ assign_attributes(resp)
62
+ end
63
+
64
+ # serialize the current state of all attributes
65
+ # method PUT
66
+ # def save
67
+ # puts name.to_s + ' .save'
68
+ # update(serialize)
69
+ # end
70
+
71
+ # method DELETE
72
+ # def destroy
73
+ # puts name.to_s + ' .destroy'
74
+ # resp = self.class.delete("/#{id}")
75
+ # end
76
+
77
+ #
78
+ # Wrapper method for the request methods of the same names
79
+ #
80
+ def self.get(tokens = '')
81
+ resp = request(:get, tokens)
82
+ return initialize_objects(resp) if resp.is_a?(Array)
83
+ return initialize_object(resp) if resp.is_a?(Hash)
84
+ raise 'Unknown response format'
85
+ end
86
+
87
+ def self.post(tokens = '', attrs)
88
+ resp = request(:post, tokens, attrs)
89
+ initialize_object(resp)
90
+ end
91
+
92
+ def self.put(tokens, attrs)
93
+ request(:put, tokens, attrs)
94
+ end
95
+
96
+ def self.delete(tokens = '')
97
+ request(:delete, tokens)
98
+ end
99
+
100
+ # def self.initialize_object(attrs)
101
+ # obj = new(attrs)
102
+ # obj.assign_attributes(attrs)
103
+ # end
104
+ #
105
+ # def self.initialize_objects(attrs_arr)
106
+ # attrs_arr.map { |attrs| initialize_object(attrs) }
107
+ # end
108
+
109
+ def self.request(verb, tokens = '', params = nil)
110
+ # puts "ApiClient::request #{verb},"\
111
+ # " #{BASE_URL}#{path}, #{params}, #{headers}"
112
+ path = method_defined?(:api_path) ? api_path : ''
113
+
114
+ response = RestClient::Request.execute(
115
+ method: verb,
116
+ url: api_url + path + tokens,
117
+ payload: params ? serialize(params) : to_json,
118
+ headers: {
119
+ content_type: 'application/json',
120
+ accept: 'application/json'
121
+ }.merge!(api_headers)
122
+ )
123
+
124
+ deserialize(response)
125
+ end
126
+
127
+ def assign_attributes(_values, _options = {})
128
+ send("#{k}=", v)
129
+ end
130
+
131
+ def serialize(payload)
132
+ # this may not always be json
133
+ # payload.to_xml
134
+ payload.to_json
135
+ end
136
+
137
+ def deserialize(payload)
138
+ # this may not always be json
139
+ # from_xml(payload)
140
+ from_json(payload)
141
+ end
142
+ end
143
+ end
144
+ require_relative './active_rest/api_model'
145
+ require_relative './active_rest/concrete_example_model'
146
+ require_relative './active_rest/other_model'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './timekit/config'
3
4
  require_relative './timekit/client'
4
5
  require_relative './timekit/authorization'
@@ -27,9 +28,11 @@ module Timekit
27
28
 
28
29
  email = configurations[:email]
29
30
  token = configurations[:api_token]
31
+ return unless email && token
32
+
30
33
  config[:credentials] = Timekit::Authorization.new(
31
34
  email, token
32
- ) if email && token
35
+ )
33
36
  end
34
37
 
35
38
  def self.calendar_client
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './app/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class App
4
5
  # Client class for the app resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Authorization
4
5
  attr_reader :email, :api_token
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './booking/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Booking
4
5
  # Client class for the booking resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './calendar/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Calendar
4
5
  # Client class for the calendar resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'base64'
3
4
 
4
5
  module Timekit
@@ -16,7 +17,7 @@ module Timekit
16
17
  #
17
18
  # Wrapper method for the timekit request methods of the same names
18
19
  #
19
- [:get, :put, :post, :delete].each do |verb|
20
+ %i[get put post delete].each do |verb|
20
21
  define_method(verb) do |path, params = {}|
21
22
  # puts "Timekit::Client::#{verb} => #{path}#{token}"
22
23
  headers = {
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Config < Hash
4
- CONFIG_KEYS = [
5
- :credentials,
6
- :app
5
+ CONFIG_KEYS = %i[
6
+ credentials
7
+ app
7
8
  ].freeze
8
9
 
9
10
  def []=(key, value)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './credential/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Credential
4
5
  # Client class for the credential resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './event/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Event
4
5
  # Client class for the event resource
@@ -42,13 +43,13 @@ module Timekit
42
43
 
43
44
  params = set_optional_params(
44
45
  binding,
45
- [
46
- :participants,
47
- :invite,
48
- :description,
49
- :my_rsvp,
50
- :sync_provider,
51
- :all_day
46
+ %i[
47
+ participants
48
+ invite
49
+ description
50
+ my_rsvp
51
+ sync_provider
52
+ all_day
52
53
  ],
53
54
  params
54
55
  )
@@ -71,11 +72,11 @@ module Timekit
71
72
 
72
73
  params = set_optional_params(
73
74
  binding,
74
- [
75
- :what,
76
- :where,
77
- :participants,
78
- :all_day
75
+ %i[
76
+ what
77
+ where
78
+ participants
79
+ all_day
79
80
  ],
80
81
  params
81
82
  )
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Filtercollection
4
- DAYS = %w(
5
+ DAYS = %w[
5
6
  Monday
6
7
  Tuesday
7
8
  Wednesday
@@ -9,7 +10,7 @@ module Timekit
9
10
  Friday
10
11
  Saturday
11
12
  Sunday
12
- ).freeze
13
+ ].freeze
13
14
 
14
15
  def initialize
15
16
  @and_conditions = []
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './findtime/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Findtime
4
5
  # Client class for the findtime resource
@@ -28,15 +29,15 @@ module Timekit
28
29
  !value.nil?
29
30
  end
30
31
 
31
- raise 'Entity id required to find time'\
32
- ' (email,user id,calendar id)' unless
33
- params[:emails] || params[:user_ids] || params[:calendar_ids]
32
+ unless params[:emails] || params[:user_ids] || params[:calendar_ids]
33
+ raise 'Entity id required to find time'\
34
+ ' (email,user id,calendar id)'
35
+ end
34
36
 
35
37
  post(API_PATH, params)
36
38
  end
37
39
 
38
- def bulk_query(queries)
39
- end
40
+ def bulk_query(queries); end
40
41
  end
41
42
  end
42
43
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Findtime
4
5
  class Filtercollections
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'singleton'
3
4
  require 'rest-client'
4
5
 
@@ -9,7 +10,7 @@ module Timekit
9
10
 
10
11
  BASE_URL = 'https://api.timekit.io/v2'
11
12
 
12
- [:get, :put, :post, :delete].each do |verb|
13
+ %i[get put post delete].each do |verb|
13
14
  define_method(verb) do |path, params, headers|
14
15
  request __method__, path, params, headers
15
16
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './user/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class User
4
5
  # Client class for the user resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  module Version
4
5
  module_function
@@ -15,7 +16,7 @@ module Timekit
15
16
 
16
17
  # @return [Integer]
17
18
  def patch
18
- 3
19
+ 5
19
20
  end
20
21
 
21
22
  # @return [Integer, NilClass]
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative './widget/client'
3
4
 
4
5
  module Timekit
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Timekit
3
4
  class Widget
4
5
  # Client class for the widget resource
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'timekit/version'
@@ -14,10 +15,10 @@ Gem::Specification.new do |s|
14
15
  s.files = ['lib/timekit.rb']
15
16
  s.homepage = 'https://github.com/mgauthier/timekit'
16
17
  s.license = 'MIT'
17
- s.require_paths = %w(lib)
18
- s.files = %w(
18
+ s.require_paths = %w[lib]
19
+ s.files = %w[
19
20
  CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md timekit.gemspec
20
- ) + Dir['lib/**/*.rb']
21
+ ] + Dir['lib/**/*.rb']
21
22
  s.version = Timekit::Version
22
23
  s.required_ruby_version = '~> 2.1'
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timekit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Gauthier
@@ -34,6 +34,10 @@ files:
34
34
  - CONTRIBUTING.md
35
35
  - LICENSE.md
36
36
  - README.md
37
+ - lib/active_rest/api_model.rb
38
+ - lib/active_rest/concrete_example_model.rb
39
+ - lib/active_rest/other_model.rb
40
+ - lib/base.rb
37
41
  - lib/timekit.rb
38
42
  - lib/timekit/app.rb
39
43
  - lib/timekit/app/client.rb