Class: TimeTree::CalendarApp::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- TimeTree::CalendarApp::Client
- Defined in:
- lib/timetree/calendar_app/client.rb
Overview
TimeTree API CalendarApp client.
Constant Summary
Constants inherited from BaseClient
Instance Attribute Summary collapse
- #application_id ⇒ String readonly
- #installation_id ⇒ Integer readonly
- #private_key ⇒ String readonly
- #token ⇒ String readonly
Attributes inherited from BaseClient
#ratelimit_limit, #ratelimit_remaining, #ratelimit_reset_at
Instance Method Summary collapse
-
#calendar(include_relationships: nil) ⇒ TimeTree::Calendar
Get a calendar information related to CalendarApp.
-
#calendar_members ⇒ Array<TimeTree::User>
Get a calendar’s member information.
-
#create_activity(event_id, params) ⇒ TimeTree::Activity
Creates a comment.
-
#create_event(params) ⇒ TimeTree::Event
Creates an event.
-
#delete_event(event_id) ⇒ true
Deletes an event.
-
#event(event_id, include_relationships: nil) ⇒ TimeTree::Event
Get an event’s information.
-
#initialize(installation_id, application_id = nil, private_key = nil) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#upcoming_events(days: 7, timezone: 'UTC', include_relationships: nil) ⇒ Array<TimeTree::Event>
Get events’ information after a request date.
-
#update_event(event_id, params) ⇒ TimeTree::Event
Updates an event.
Methods inherited from BaseClient
Constructor Details
#initialize(installation_id, application_id = nil, private_key = nil) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 |
# File 'lib/timetree/calendar_app/client.rb', line 22 def initialize(installation_id, application_id = nil, private_key = nil) @installation_id = installation_id @application_id = application_id || TimeTree.configuration.calendar_app_application_id @private_key = OpenSSL::PKey::RSA.new((private_key || TimeTree.configuration.calendar_app_private_key).to_s) check_client_requirement @http_cmd = HttpCommand.new(API_HOST, self) rescue OpenSSL::PKey::RSAError raise Error.new 'private_key must be RSA private key.' end |
Instance Attribute Details
#application_id ⇒ String (readonly)
13 14 15 |
# File 'lib/timetree/calendar_app/client.rb', line 13 def application_id @application_id end |
#installation_id ⇒ Integer (readonly)
11 12 13 |
# File 'lib/timetree/calendar_app/client.rb', line 11 def installation_id @installation_id end |
#private_key ⇒ String (readonly)
15 16 17 |
# File 'lib/timetree/calendar_app/client.rb', line 15 def private_key @private_key end |
#token ⇒ String (readonly)
17 18 19 |
# File 'lib/timetree/calendar_app/client.rb', line 17 def token @token end |
Instance Method Details
#calendar(include_relationships: nil) ⇒ TimeTree::Calendar
Get a calendar information related to CalendarApp
includes association’s object in the response.
40 41 42 43 44 45 46 47 |
# File 'lib/timetree/calendar_app/client.rb', line 40 def calendar(include_relationships: nil) check_access_token params = relationships_params(include_relationships, Calendar::RELATIONSHIPS) res = http_cmd.get('/calendar', params) raise ApiError.new(res) if res.status != 200 to_model(res.body[:data], included: res.body[:included]) end |
#calendar_members ⇒ Array<TimeTree::User>
Get a calendar’s member information.
55 56 57 58 59 60 61 |
# File 'lib/timetree/calendar_app/client.rb', line 55 def calendar_members check_access_token res = http_cmd.get('/calendar/members') raise ApiError.new(res) if res.status != 200 res.body[:data].map { |item| to_model(item) } end |
#create_activity(event_id, params) ⇒ TimeTree::Activity
Creates a comment.
comment’s information specified in TimeTree request body format.
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/timetree/calendar_app/client.rb', line 166 def create_activity(event_id, params) check_event_id event_id check_access_token res = http_cmd.post("/calendar/events/#{event_id}/activities", params) raise ApiError.new(res) if res.status != 201 activity = to_model(res.body[:data]) activity.event_id = event_id activity end |
#create_event(params) ⇒ TimeTree::Event
Creates an event.
112 113 114 115 116 117 118 |
# File 'lib/timetree/calendar_app/client.rb', line 112 def create_event(params) check_access_token res = http_cmd.post('/calendar/events', params) raise ApiError.new(res) if res.status != 201 to_model(res.body[:data]) end |
#delete_event(event_id) ⇒ true
Deletes an event.
147 148 149 150 151 152 153 154 |
# File 'lib/timetree/calendar_app/client.rb', line 147 def delete_event(event_id) check_event_id event_id check_access_token res = http_cmd.delete("/calendar/events/#{event_id}") raise ApiError.new(res) if res.status != 204 true end |
#event(event_id, include_relationships: nil) ⇒ TimeTree::Event
Get an event’s information.
includes association’s object in the response.
73 74 75 76 77 78 79 80 81 |
# File 'lib/timetree/calendar_app/client.rb', line 73 def event(event_id, include_relationships: nil) check_event_id event_id check_access_token params = relationships_params(include_relationships, Event::RELATIONSHIPS) res = http_cmd.get("/calendar/events/#{event_id}", params) raise ApiError.new(res) if res.status != 200 to_model(res.body[:data], included: res.body[:included]) end |
#inspect ⇒ Object
177 178 179 180 181 182 183 184 185 186 |
# File 'lib/timetree/calendar_app/client.rb', line 177 def inspect limit_info = nil if defined?(@ratelimit_limit) && @ratelimit_limit limit_info = " ratelimit:#{ratelimit_remaining}/#{ratelimit_limit}" end if defined?(@ratelimit_reset_at) && @ratelimit_reset_at limit_info = "#{limit_info}, reset_at:#{ratelimit_reset_at.strftime('%m/%d %R')}" end "\#<#{self.class}:#{object_id}#{limit_info}>" end |
#upcoming_events(days: 7, timezone: 'UTC', include_relationships: nil) ⇒ Array<TimeTree::Event>
Get events’ information after a request date.
includes association’s object in the response.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/timetree/calendar_app/client.rb', line 93 def upcoming_events(days: 7, timezone: 'UTC', include_relationships: nil) check_access_token params = relationships_params(include_relationships, Event::RELATIONSHIPS) params.merge!(days: days, timezone: timezone) res = http_cmd.get('/calendar/upcoming_events', params) raise ApiError.new(res) if res.status != 200 included = res.body[:included] res.body[:data].map { |item| to_model(item, included: included) } end |
#update_event(event_id, params) ⇒ TimeTree::Event
Updates an event.
event’s information specified in TimeTree request body format.
130 131 132 133 134 135 136 137 |
# File 'lib/timetree/calendar_app/client.rb', line 130 def update_event(event_id, params) check_event_id event_id check_access_token res = http_cmd.put("/calendar/events/#{event_id}", params) raise ApiError.new(res) if res.status != 200 to_model(res.body[:data]) end |