Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds attachments resource #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
.DS_Store
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 :Attachment, 'bcx/resources/attachment'
end

module Client
Expand Down
1 change: 1 addition & 0 deletions lib/bcx/client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class HTTP < Rapidash::Client
resource :projects, class_name: 'Bcx::Resources::Project'
resource :todolists, class_name: 'Bcx::Resources::Todolist'
resource :people, class_name: 'Bcx::Resources::Person'
resource :attachments, class_name: 'Bcx::Resources::Attachment'

def initialize(options = {})
@account = Bcx.configuration.account
Expand Down
1 change: 1 addition & 0 deletions lib/bcx/client/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class OAuth < Rapidash::Client
resource :projects, class_name: 'Bcx::Resources::Project'
resource :todolists, class_name: 'Bcx::Resources::Todolist'
resource :people, class_name: 'Bcx::Resources::Person'
resource :attachments, class_name: 'Bcx::Resources::Attachment'

def initialize(options = {})
@account = options[:account] || Bcx.configuration.account
Expand Down
35 changes: 35 additions & 0 deletions lib/bcx/resources/attachment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# ## Attachment
#
# Provides access to attachments
#
# #### Geta all attachments across all projects
# `GET /attachments.json`
#
# client.attachments!
#
# #### Get all atatchments on a specific project
# `GET /projects/:project_id/attachments.json`
#
# client.projects(123).attachments!
#
# #### Get a specific attachment
# `GET /projects/:project_id/attachments/:attachment_id.json`
#
# client.project(123).attachments!(456)
#
# #### Rename an existing attachment
# `PUT /projects/:project_id/attachments/:attachment_id.json`
#
# client.project(123).attachments(456).update!( name: "Updated name" )
#
# #### Delete an existing attachment
# `DELETE /projects/:project_id/attachments/:attachment_id.json`
#
# client.project(123).attachments(456).delete!
#
module Bcx
module Resources
class Attachment < Rapidash::Base
end
end
end
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 :attachments

collection :archived
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bcx/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Bcx
VERSION = "1.1.0"
VERSION = "1.2.0"
end
51 changes: 51 additions & 0 deletions spec/bcx/attachment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "spec_helper"

describe Bcx::Resources::Attachment, :vcr do
let(:client) { Bcx::Client::HTTP.new(login: 'bcx-test-user', password: 'secret') }

describe "GET /attachments.json" do
let (:attachments) { client.attachments! }

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

it "first attachment should have correct title" do
expect(attachments.first.name). to eql "bigbasecamplogo.png"
end

end

describe "GET /projects/10268857/attachments/176354961.json" do
let(:attachment) { client.projects(10268857).attachments!(176354961) }

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

it "should have the correct id" do
expect(attachment.id).to eq 176354961
end
end

describe "DELETE /projects/10268857/attachments/176355933.json" do
let(:attachment) { client.projects(10268857).attachments(176355933) }

it "should delete an attachment" do
expect { attachment.delete! }.to_not raise_error
expect(client.projects(10268857).attachments!(176355933).trashed).to be true
end
end

describe "PUT /projects/10268857/attachments/176354961.json" do
let(:attachment) { client.projects(10268857).attachments(176354961) }

it "renames an attachment" do
expect(attachment.call!.name). to eql "bigbasecamplogo.png"
expect{ attachment.update!(name: "smallbasecamplogo.png") }.to_not raise_error
expect(attachment.call!.name).to eql "smallbasecamplogo.png"
end
end

describe
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