Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bcx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'vcr'
gem.add_development_dependency 'webmock'
end
1 change: 1 addition & 0 deletions lib/bcx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Resources
autoload :Access, 'bcx/resources/access'
autoload :Authorization, 'bcx/resources/authorization'
autoload :Comment, 'bcx/resources/comment'
autoload :CalendarEvent, 'bcx/resources/calendar_event'
end

module Client
Expand Down
60 changes: 60 additions & 0 deletions lib/bcx/resources/calendar_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# ## Calendar Events
#
# Provides access to calendar events resoource and other nested resources
# Calendar Events are associated with either a Project, or with a user's
# Calendar. At present, only Project Calendar Events are implemented by this
# API client.
#
# #### Fetch upcoming calendar events for a given project
# `GET /projects/123/calendar_events.json`
#
# client.projects(123).calendar_events!
#
# #### Fetch past calendar events for a given project
# `GET /projects/123/calendar_events/past.json`
#
# client.projects(123).calendar_events.past!
#
# #### Fetch single calendar event for a given project with ID of 456
# `GET /projects/123/calendar_events/456.json`
#
# client.projects(123).calendar_events!(456)
#
# #### Create a calendar event for a given project
# `POST /projects/123/calendar_events.json`
#
# client.projects(123).calendar_events.create!(options)
#
# where `options` is a hash like the following,
#
# ```
# {
# "summary": "My single, all-day event",
# "description": "Details to follow",
# "all_day": true,
# "starts_at": "2012-03-28"
# }
# ```
#
# See the [New Basecamp API docs](https://github.com/basecamp/bcx-api/blob/master/sections/calendar_events.md#create-calendar-event) for more detailed exmaples.
#
# #### Update an existing calendar event for a given project
# `PUT /projects/123/calendar_events/456.json`
#
# client.projects(123).calendar_events(456).update!(options)
#
# #### Delete a calendar event
# `DELETE /projects/123/calendar_events/456.json`
#
# client.projects(123).calendar_events(456).delete!
#
module Bcx
module Resources
class CalendarEvent < Rapidash::Base
url :calendar_events
resource :comments

collection :past
end
end
end
4 changes: 4 additions & 0 deletions lib/bcx/resources/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#
# client.projects(123).todos(456).comments.create!(content: 'New comment')
#
# #### Create a new calendar event comment
# `POST /projects/123/calendar_events/456/comments.json`
#
# client.projects(123).calendar_events(456).comments.create!(content: 'New comment')
#
# #### Delete the comment
# `DELETE /projects/123/comments/456.json`
Expand Down
1 change: 1 addition & 0 deletions lib/bcx/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Project < Rapidash::Base
resource :todos
resource :accesses
resource :comments
resource :calendar_events

collection :archived
end
Expand Down
79 changes: 79 additions & 0 deletions spec/bcx/calendar_event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
load 'vcr.rb'
load 'bcx.rb'

VCR.configure do |c|
c.cassette_library_dir = 'spec/cassettes'
c.hook_into :webmock
c.default_cassette_options = { record: :new_episodes }
c.configure_rspec_metadata!
end

RSpec.configure do |config|
config.before(:each) do
# Set to test account
Bcx.configure { |config| config.account = '3015337' }
end
end

describe Bcx::Resources::CalendarEvent, :vcr do

let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user@mailinator.com', password: 'supersecret') }

# WARNING this test creates a calendar event, which is then used in later tests
describe "POST /projects/10215131/calendar_events.json" do
it "should create a new calendar event" do
calendar_event = client.projects(10215131).calendar_events.create!(summary: 'My calendar event', all_day: true, starts_at: Date.today)
expect(calendar_event.created_at).not_to be_blank
expect(calendar_event.summary).to eq 'My calendar event'
end
end

describe "POST /projects/10215131/calendar_events.json" do
it "should create a new comment for a calendar event" do
comment = client.projects(10215131).calendar_events(21015316).comments.create!(content: "WOW!")
expect(comment.created_at).not_to be_blank
expect(comment.content).to eq 'WOW!'
end
end

describe "GET /projects/10215131/calendar_events/21015316.json" do
let(:calendar_event) { client.projects(10215131).calendar_events!(21015316) }

it "should return a hash" do
expect(calendar_event).to be_a Hashie::Mash
end

it "should have the correct id" do
expect(calendar_event.id).to eq 21015316
expect(calendar_event.summary).to eq 'My calendar event'
end
end

describe "GET /projects/10215131/calendar_events/past" do
let(:calendar_events) { client.projects(10215131).calendar_events.past! }

it "should be an array" do
expect(calendar_events).to be_an Array
end

it "should be empty" do
expect(calendar_events).to be_empty
end
end

describe "PUT /projects/10215131/calendar_events/21015316.json" do
it "should update an existing calendar event" do
calendar_event = client.projects(10215131).calendar_events(21015316).update!(summary: 'My updated calendar event')
expect(calendar_event.summary).to eq 'My updated calendar event'
end
end

describe "DELETE /projects/10215131/calendar_events/21015316.json" do
it "should trash the given calendar event" do
client.projects(10215131).calendar_events(21015316).delete!
calendar_event = client.projects(10215131).calendar_events!(21015316)
expect(calendar_event.trashed).to be true
end
end

end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading