boardeffect 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8678828b354b65de0b58c85567ca5c99fcc93ff
4
+ data.tar.gz: 0eec7f5fa237b33b279609077dd52a317a03a857
5
+ SHA512:
6
+ metadata.gz: 1a1f7f0dc746bc9c820e00b61f75f6cac91446659de3564ede647e64851c3724e6ae0bb4815e4d2f6bd07aa1250703305347a523e241512f19a52f4ff32836bb
7
+ data.tar.gz: 01421f98f9ea3b3bb8a663c0c1cda54e98f40c0ed308273b5e4d5ccc19b166f0a4c9ce9958ce0f7c18bb236f89afce48e96c5018d7492b71efc8ba29246e7b67
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ bin*
3
+ pkg
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Mark Hunt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # boardeffect
2
+
3
+ Ruby client for [Version 2 of the BoardEffect API].
4
+
5
+
6
+ ## Install
7
+
8
+ ```
9
+ $ gem install boardeffect
10
+ ```
11
+
12
+
13
+ ## Quick start
14
+
15
+ ```ruby
16
+ require 'boardeffect'
17
+
18
+ boardeffect = BoardEffect::Client.new(access_token: 'YOUR PERSONAL ACCESS TOKEN', host: 'https://yourportalname.boardeffect.com/')
19
+ ```
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :spec
5
+
6
+ Rake::TestTask.new(:spec) do |t|
7
+ t.test_files = FileList['spec/*_spec.rb']
8
+ t.warning = true
9
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'boardeffect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "boardeffect"
8
+ spec.version = BoardEffect::VERSION
9
+ spec.authors = ['Mark Hunt']
10
+ spec.email = ['development@boardeffect.com']
11
+ spec.homepage = 'https://github.com/magicmarkker/boardeffect'
12
+ spec.description = 'Ruby client for Version 2 of the BoardEffect API'
13
+ spec.summary = 'Ruby client for Version 2 of the BoardEffect API'
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'rake', '~> 10.4'
22
+ spec.add_development_dependency 'webmock', '~> 1.24'
23
+ spec.add_development_dependency 'minitest', '~> 5.0'
24
+ end
@@ -0,0 +1,37 @@
1
+ require 'boardeffect/client'
2
+ require 'boardeffect/version'
3
+
4
+ module BoardEffect
5
+ class Client
6
+
7
+ # Announcements
8
+ def get_announcements(params = nil)
9
+ get("/services/v2/#{workroom_check(params)}announcements.json", params)
10
+ end
11
+
12
+ def create_announcement(attributes, params = nil)
13
+ post("/services/v2/#{workroom_check(params)}announcements.json", attributes)
14
+ end
15
+
16
+ def update_announcement(announcement_id, attributes, params = nil)
17
+ put("/services/v2/#{workroom_check(params)}announcements/#{announcement_id}.json", attributes)
18
+ end
19
+
20
+ def get_announcement(announcement_id, params = nil)
21
+ get("/services/v2/#{workroom_check(params)}announcements/#{announcement_id}.json")
22
+ end
23
+
24
+ def delete_announcement(announcement_id, params = nil)
25
+ delete("/services/v2/#{workroom_check(params)}announcements/#{announcement_id}.json")
26
+ end
27
+
28
+ private
29
+
30
+ def workroom_check(params = nil)
31
+ if !params.nil? && params.key?('workroom_id')
32
+ raise Error, "Workroom ID Can not be 0" if params[:workroom_id].to_i == 0
33
+ "workrooms/#{params[:workroom_id].to_i}/"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,95 @@
1
+ require 'boardeffect/errors'
2
+ require 'boardeffect/record'
3
+ require 'net/http'
4
+ require 'cgi'
5
+ require 'json'
6
+
7
+ module BoardEffect
8
+ class Client
9
+ def initialize(options = {})
10
+ if options.key?(:access_token)
11
+ @auth_header, @auth_value = 'Authorization', "Token token=#{options[:access_token]}"
12
+ else
13
+ @auth_header, @auth_value = 'X-BoardEffectToken', options.fetch(:token)
14
+ end
15
+
16
+ @user_agent = options.fetch(:user_agent, 'Ruby BoardEffect::Client')
17
+
18
+ @host = (options.key?(:host)) ? options[:host] : 'boardeffect.local'
19
+
20
+ @http = Net::HTTP.new(@host)
21
+
22
+ @http.use_ssl = (options.key?(:host)) ? true : false
23
+ end
24
+
25
+ def get(path, params = nil)
26
+ request(Net::HTTP::Get.new(request_uri(path, params)))
27
+ end
28
+
29
+ private
30
+
31
+ def post(path, attributes)
32
+ request(Net::HTTP::Post.new(path), attributes)
33
+ end
34
+
35
+ def put(path, attributes = nil)
36
+ request(Net::HTTP::Put.new(path), attributes)
37
+ end
38
+
39
+ def delete(path)
40
+ request(Net::HTTP::Delete.new(path))
41
+ end
42
+
43
+ def request(http_request, body_object = nil)
44
+ http_request['User-Agent'] = @user_agent
45
+ http_request[@auth_header] = @auth_value
46
+
47
+ if body_object
48
+ http_request['Content-Type'] = 'application/json'
49
+ http_request.body = JSON.generate(body_object)
50
+ end
51
+
52
+ parse(@http.request(http_request))
53
+ end
54
+
55
+ def parse(http_response)
56
+ case http_response
57
+ when Net::HTTPNoContent
58
+ :no_content
59
+ when Net::HTTPSuccess
60
+ if http_response['Content-Type'] && http_response['Content-Type'].split(';').first == 'application/json'
61
+ JSON.parse(http_response.body, symbolize_names: true, object_class: Record).tap do |object|
62
+ if http_response['Link'] && next_page = http_response['Link'][/<([^>]+)>; rel="next"/, 1]
63
+ object.singleton_class.module_eval { attr_accessor :next_page }
64
+ object.next_page = URI.parse(next_page).request_uri
65
+ end
66
+ end
67
+ else
68
+ http_response.body
69
+ end
70
+ when Net::HTTPBadRequest
71
+ object = JSON.parse(http_response.body, symbolize_names: true)
72
+
73
+ raise Error, "boardeffect api error: #{object.fetch(:message)}"
74
+ when Net::HTTPUnauthorized
75
+ raise AuthenticationError
76
+ else
77
+ raise Error, "boardeffect api error: unexpected #{http_response.code} response from #{@host}"
78
+ end
79
+ end
80
+
81
+ def request_uri(path, params = nil)
82
+ return path if params.nil? || params.empty?
83
+
84
+ path + '?' + params.map { |k, v| "#{escape(k)}=#{array_escape(v)}" }.join('&')
85
+ end
86
+
87
+ def array_escape(object)
88
+ Array(object).map { |value| escape(value) }.join(',')
89
+ end
90
+
91
+ def escape(component)
92
+ CGI.escape(component.to_s)
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ module BoardEffect
2
+ class Error < StandardError; end
3
+
4
+ class AuthenticationError < Error; end
5
+ end
@@ -0,0 +1,31 @@
1
+ module BoardEffect
2
+ class Record
3
+ def initialize
4
+ @attributes = {}
5
+ end
6
+
7
+ def [](name)
8
+ @attributes[name]
9
+ end
10
+
11
+ def []=(name, value)
12
+ @attributes[name] = value
13
+ end
14
+
15
+ def method_missing(name, *args, &block)
16
+ if @attributes.has_key?(name) && args.empty? && block.nil?
17
+ return @attributes[name]
18
+ else
19
+ super name, *args, &block
20
+ end
21
+ end
22
+
23
+ def respond_to_missing?(name, include_private = false)
24
+ @attributes.has_key?(name)
25
+ end
26
+
27
+ def to_h
28
+ @attributes
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module BoardEffect
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,98 @@
1
+ require 'minitest/autorun'
2
+ require 'webmock/minitest'
3
+ require 'boardeffect'
4
+
5
+ describe 'BoardEffect::Client' do
6
+ before do
7
+ @token = 'd9e982b84b624ab761f718a54f5ab682b0dbf9a11e28ed334812a118eeba34ab2200ec00a923b85eb7c848343aadc601b0386b8ea875f7feb931e2674ceaaf8b'
8
+
9
+ @base_url = 'http://boardeffect.local/services/v2'
10
+
11
+ @entry_id = @project_id = @id = 1234
12
+
13
+ @auth_header = {headers: {'Authorization' => "Token token=#{@token}", 'User-Agent'=>'Ruby BoardEffect::Client', 'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}}
14
+
15
+ @json_request = {headers: {'Authorization' => "Token token=#{@token}", 'User-Agent'=>'Ruby BoardEffect::Client', 'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'}}
16
+
17
+ @json_response = {headers: {'Content-Type' => 'application/json;charset=utf-8'}, body: '{}'}
18
+
19
+ @client = BoardEffect::Client.new(access_token: @token)
20
+ end
21
+
22
+ after do
23
+ assert_requested(@request) if defined?(@request)
24
+ end
25
+
26
+ describe "get_announcements method" do
27
+ it "fetches the announcements resources and returns the decoded response object" do
28
+ @request = stub_request(:get, "#@base_url/announcements").with(@auth_header).to_return(@json_response.merge(body: '[]'))
29
+ @client.get_announcements.must_equal([])
30
+ end
31
+
32
+ it 'makes request to get specific workroom announcements' do
33
+ @request = stub_request(:get, "#@base_url/announcements?workroom_id=1")
34
+ @client.get_announcements(workroom_id: "1")
35
+ end
36
+
37
+ it 'raises an error if workroom_id is 0' do
38
+ message = "Workroom ID Can not be 0"
39
+ @request = stub_request(:get, "#@base_url/announcements?workroom_id=0").to_return(@json_response.merge(status: 400, body: %({"message":"#{message}"})))
40
+ exception = proc { @client.get_announcements(workroom_id: "0") }.must_raise(BoardEffect::Error)
41
+ exception.message.must_include(message)
42
+ end
43
+ end
44
+
45
+ describe "create_announcement method" do
46
+ it "posts the given attributes to the announcements resource and returns the decoded response object" do
47
+ @request = stub_request(:post, "#@base_url/announcements").with(@json_request.merge(body: { title: "Testing api", body: "This is a description"})).to_return(@json_response.merge(status: 201))
48
+ @client.create_announcement(title: "Testing api", body: "This is a description").must_be_instance_of(BoardEffect::Record)
49
+ end
50
+ end
51
+
52
+ describe "update_announcement method" do
53
+ it "puts the given attributes to the announcements resource and returns the decoded response object" do
54
+ @request = stub_request(:put, "#@base_url/announcements/1").with(@json_request.merge(body: { title: "Testing api update", body: "This is a description"})).to_return(@json_response.merge(status: 201))
55
+ @client.update_announcement(1, {title: "Testing api update", body: "This is a description"}).must_be_instance_of(BoardEffect::Record)
56
+ end
57
+ end
58
+
59
+ describe "get_announcement method" do
60
+ it "fetches the announcement resources and returns the decoded response object" do
61
+ @request = stub_request(:get, "#@base_url/announcements/1").with(@auth_header).to_return(@json_response.merge(body: '[]'))
62
+ @client.get_announcement(1).must_equal([])
63
+ end
64
+ end
65
+
66
+ describe "delete_announcement method" do
67
+ it "deletes the announcement resource" do
68
+ @request = stub_request(:delete, "#@base_url/announcements/1").with(@auth_header).to_return(status: 204)
69
+ @client.delete_announcement(1).must_equal(:no_content)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'BoardEffect::Record' do
75
+ before do
76
+ @record = BoardEffect::Record.new
77
+
78
+ @record[:project_id] = 123
79
+ end
80
+
81
+ describe 'square brackets method' do
82
+ it 'returns the value of the attribute with the given name' do
83
+ @record[:project_id].must_equal(123)
84
+ end
85
+ end
86
+
87
+ describe 'method_missing' do
88
+ it 'returns the value of the attribute with the given name' do
89
+ @record.project_id.must_equal(123)
90
+ end
91
+ end
92
+
93
+ describe 'to_h method' do
94
+ it 'returns a hash containing the record attributes' do
95
+ @record.to_h.must_equal({project_id: 123})
96
+ end
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boardeffect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Hunt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.24'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.24'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Ruby client for Version 2 of the BoardEffect API
56
+ email:
57
+ - development@boardeffect.com
58
+ executables:
59
+ - console
60
+ - setup
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - boardeffect.gemspec
74
+ - lib/boardeffect.rb
75
+ - lib/boardeffect/client.rb
76
+ - lib/boardeffect/errors.rb
77
+ - lib/boardeffect/record.rb
78
+ - lib/boardeffect/version.rb
79
+ - spec/boardeffect_spec.rb
80
+ homepage: https://github.com/magicmarkker/boardeffect
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.5.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Ruby client for Version 2 of the BoardEffect API
104
+ test_files:
105
+ - spec/boardeffect_spec.rb