Class: TimeTree::OAuthApp::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- TimeTree::OAuthApp::Client
- Defined in:
- lib/timetree/oauth_app/client.rb
Overview
TimeTree API OAuthApp client.
Constant Summary
Constants inherited from BaseClient
Instance Attribute Summary collapse
- #token ⇒ String readonly
Attributes inherited from BaseClient
#ratelimit_limit, #ratelimit_remaining, #ratelimit_reset_at
Instance Method Summary collapse
-
#calendar(cal_id, include_relationships: nil) ⇒ TimeTree::Calendar
Get a single calendar’s information.
-
#calendar_labels(cal_id) ⇒ Array<TimeTree::Label>
Get a calendar’s label information used in event.
-
#calendar_members(cal_id) ⇒ Array<TimeTree::User>
Get a calendar’s member information.
-
#calendars(include_relationships: nil) ⇒ Array<TimeTree::Calendar>
Get calendar list that current user can access.
-
#create_activity(cal_id, event_id, params) ⇒ TimeTree::Activity
Creates comment to an event.
-
#create_event(cal_id, params) ⇒ TimeTree::Event
Creates an event to the calendar.
-
#current_user ⇒ TimeTree::User
Get current user information.
-
#delete_event(cal_id, event_id) ⇒ true
Deletes an event.
-
#event(cal_id, event_id, include_relationships: nil) ⇒ TimeTree::Event
Get the event’s information.
-
#initialize(token = nil) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
-
#upcoming_events(cal_id, days: 7, timezone: 'UTC', include_relationships: nil) ⇒ Array<TimeTree::Event>
Get the events’ information after a request date.
-
#update_event(cal_id, event_id, params) ⇒ TimeTree::Event
Updates an event.
Methods inherited from BaseClient
Constructor Details
#initialize(token = nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 |
# File 'lib/timetree/oauth_app/client.rb', line 11 def initialize(token = nil) @token = token || TimeTree.configuration.oauth_app_token check_token @http_cmd = HttpCommand.new(API_HOST, self) end |
Instance Attribute Details
#token ⇒ String (readonly)
8 9 10 |
# File 'lib/timetree/oauth_app/client.rb', line 8 def token @token end |
Instance Method Details
#calendar(cal_id, include_relationships: nil) ⇒ TimeTree::Calendar
Get a single calendar’s information.
includes association’s object in the response.
40 41 42 43 44 45 46 47 |
# File 'lib/timetree/oauth_app/client.rb', line 40 def calendar(cal_id, include_relationships: nil) check_calendar_id cal_id params = relationships_params(include_relationships, Calendar::RELATIONSHIPS) res = @http_cmd.get "/calendars/#{cal_id}", params raise ApiError.new(res) if res.status != 200 to_model(res.body[:data], included: res.body[:included]) end |
#calendar_labels(cal_id) ⇒ Array<TimeTree::Label>
Get a calendar’s label information used in event.
74 75 76 77 78 79 80 |
# File 'lib/timetree/oauth_app/client.rb', line 74 def calendar_labels(cal_id) check_calendar_id cal_id res = @http_cmd.get "/calendars/#{cal_id}/labels" raise ApiError.new(res) if res.status != 200 res.body[:data].map { |item| to_model(item) } end |
#calendar_members(cal_id) ⇒ Array<TimeTree::User>
Get a calendar’s member information.
90 91 92 93 94 95 96 |
# File 'lib/timetree/oauth_app/client.rb', line 90 def calendar_members(cal_id) check_calendar_id cal_id res = @http_cmd.get "/calendars/#{cal_id}/members" raise ApiError.new(res) if res.status != 200 res.body[:data].map { |item| to_model item } end |
#calendars(include_relationships: nil) ⇒ Array<TimeTree::Calendar>
Get calendar list that current user can access.
includes association’s object in the response.
57 58 59 60 61 62 63 64 |
# File 'lib/timetree/oauth_app/client.rb', line 57 def calendars(include_relationships: nil) params = relationships_params(include_relationships, Calendar::RELATIONSHIPS) res = @http_cmd.get '/calendars', params raise ApiError.new(res) if res.status != 200 included = res.body[:included] res.body[:data].map { |item| to_model(item, included: included) } end |
#create_activity(cal_id, event_id, params) ⇒ TimeTree::Activity
Creates comment to an event.
comment’s information specified in TimeTree request body format.
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/timetree/oauth_app/client.rb', line 222 def create_activity(cal_id, event_id, params) check_calendar_id cal_id check_event_id event_id res = @http_cmd.post "/calendars/#{cal_id}/events/#{event_id}/activities", params raise ApiError.new(res) if res.status != 201 activity = to_model res.body[:data] activity.calendar_id = cal_id activity.event_id = event_id activity end |
#create_event(cal_id, params) ⇒ TimeTree::Event
Creates an event to the calendar.
158 159 160 161 162 163 164 165 166 |
# File 'lib/timetree/oauth_app/client.rb', line 158 def create_event(cal_id, params) check_calendar_id cal_id res = @http_cmd.post "/calendars/#{cal_id}/events", params raise ApiError.new(res) if res.status != 201 ev = to_model res.body[:data] ev.calendar_id = cal_id ev end |
#current_user ⇒ TimeTree::User
Get current user information.
23 24 25 26 27 28 |
# File 'lib/timetree/oauth_app/client.rb', line 23 def current_user res = @http_cmd.get '/user' raise ApiError.new(res) if res.status != 200 to_model res.body[:data] end |
#delete_event(cal_id, event_id) ⇒ true
Deletes an event.
201 202 203 204 205 206 207 208 |
# File 'lib/timetree/oauth_app/client.rb', line 201 def delete_event(cal_id, event_id) check_calendar_id cal_id check_event_id event_id res = @http_cmd.delete "/calendars/#{cal_id}/events/#{event_id}" raise ApiError.new(res) if res.status != 204 true end |
#event(cal_id, event_id, include_relationships: nil) ⇒ TimeTree::Event
Get the event’s information.
includes association’s object in the response.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/timetree/oauth_app/client.rb', line 110 def event(cal_id, event_id, include_relationships: nil) check_calendar_id cal_id check_event_id event_id params = relationships_params(include_relationships, Event::RELATIONSHIPS) res = @http_cmd.get "/calendars/#{cal_id}/events/#{event_id}", params raise ApiError.new(res) if res.status != 200 ev = to_model(res.body[:data], included: res.body[:included]) ev.calendar_id = cal_id ev end |
#inspect ⇒ Object
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/timetree/oauth_app/client.rb', line 234 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(cal_id, days: 7, timezone: 'UTC', include_relationships: nil) ⇒ Array<TimeTree::Event>
Get the events’ information after a request date.
includes association’s object in the response.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/timetree/oauth_app/client.rb', line 134 def upcoming_events(cal_id, days: 7, timezone: 'UTC', include_relationships: nil) check_calendar_id cal_id params = relationships_params(include_relationships, Event::RELATIONSHIPS) params.merge!(days: days, timezone: timezone) res = @http_cmd.get "/calendars/#{cal_id}/upcoming_events", params raise ApiError.new(res) if res.status != 200 included = res.body[:included] res.body[:data].map do |item| ev = to_model(item, included: included) ev.calendar_id = cal_id ev end end |
#update_event(cal_id, event_id, params) ⇒ TimeTree::Event
Updates an event.
event’s information specified in TimeTree request body format.
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/timetree/oauth_app/client.rb', line 180 def update_event(cal_id, event_id, params) check_calendar_id cal_id check_event_id event_id res = @http_cmd.put "/calendars/#{cal_id}/events/#{event_id}", params raise ApiError.new(res) if res.status != 200 ev = to_model res.body[:data] ev.calendar_id = cal_id ev end |