caseblocks_api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'httparty'
7
+
8
+ group :development, :test do
9
+ gem 'pry'
10
+ gem 'webmock'
11
+ end
12
+
13
+ # Add dependencies to develop your gem here.
14
+ # Include everything needed to run rake, tests, features, etc.
15
+ group :development do
16
+ gem "rspec", "~> 2.8.0"
17
+ gem "rdoc", "~> 3.12"
18
+ gem "bundler"
19
+ gem "jeweler", "~> 1.8.4"
20
+ gem 'guard-rspec'
21
+ gem 'growl'
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.8)
5
+ coderay (1.0.7)
6
+ crack (0.3.1)
7
+ diff-lcs (1.1.3)
8
+ ffi (1.0.11)
9
+ git (1.2.5)
10
+ growl (1.0.3)
11
+ guard (1.2.3)
12
+ listen (>= 0.4.2)
13
+ thor (>= 0.14.6)
14
+ guard-rspec (1.1.0)
15
+ guard (>= 1.1)
16
+ httparty (0.8.3)
17
+ multi_json (~> 1.0)
18
+ multi_xml
19
+ jeweler (1.8.4)
20
+ bundler (~> 1.0)
21
+ git (>= 1.2.5)
22
+ rake
23
+ rdoc
24
+ json (1.7.3)
25
+ listen (0.4.7)
26
+ rb-fchange (~> 0.0.5)
27
+ rb-fsevent (~> 0.9.1)
28
+ rb-inotify (~> 0.8.8)
29
+ method_source (0.7.1)
30
+ multi_json (1.3.6)
31
+ multi_xml (0.5.1)
32
+ pry (0.9.9.6)
33
+ coderay (~> 1.0.5)
34
+ method_source (~> 0.7.1)
35
+ slop (>= 2.4.4, < 3)
36
+ rake (0.9.2.2)
37
+ rb-fchange (0.0.5)
38
+ ffi
39
+ rb-fsevent (0.9.1)
40
+ rb-inotify (0.8.8)
41
+ ffi (>= 0.5.0)
42
+ rdoc (3.12)
43
+ json (~> 1.4)
44
+ rspec (2.8.0)
45
+ rspec-core (~> 2.8.0)
46
+ rspec-expectations (~> 2.8.0)
47
+ rspec-mocks (~> 2.8.0)
48
+ rspec-core (2.8.0)
49
+ rspec-expectations (2.8.0)
50
+ diff-lcs (~> 1.1.2)
51
+ rspec-mocks (2.8.0)
52
+ slop (2.4.4)
53
+ thor (0.15.4)
54
+ webmock (1.8.7)
55
+ addressable (>= 2.2.7)
56
+ crack (>= 0.1.7)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler
63
+ growl
64
+ guard-rspec
65
+ httparty
66
+ jeweler (~> 1.8.4)
67
+ pry
68
+ rdoc (~> 3.12)
69
+ rspec (~> 2.8.0)
70
+ webmock
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 EmergeAdapt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = caseblocks_api
2
+
3
+ Authenticate with CaseBlocks:
4
+
5
+ `caseblocks = CaseBlocksAPI::Client.new("email@test.com", "some_password")`
6
+
7
+ Create a new Case:
8
+
9
+ `caseblocks.create_case({:title => "This is a Case!", :due_at => "tomorrow")`
10
+
11
+ Description goes here.
12
+
13
+ == Contributing to caseblocks_api
14
+
15
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
16
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
17
+ * Fork the project.
18
+ * Start a feature/bugfix branch.
19
+ * Commit and push until you are happy with your contribution.
20
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2012 EmergeAdapt. See LICENSE.txt for
26
+ further details.
27
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "caseblocks_api"
18
+ gem.homepage = "http://github.com/EmergeAdapt/caseblocks_api"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby wrapper for CaseBlocks API}
21
+ gem.email = "development@emergeadapt.com"
22
+ gem.authors = ["Mark Provan"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rspec/core'
28
+ require 'rspec/core/rake_task'
29
+ RSpec::Core::RakeTask.new(:spec) do |spec|
30
+ spec.pattern = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :default => :spec
39
+
40
+ require 'rdoc/task'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "caseblocks_api #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "caseblocks_api"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mark Provan"]
12
+ s.date = "2012-08-03"
13
+ s.email = "development@emergeadapt.com"
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".rspec",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "Guardfile",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "caseblocks_api.gemspec",
29
+ "lib/caseblocks_api.rb",
30
+ "lib/caseblocks_api/authentication_exception.rb",
31
+ "spec/caseblocks_api_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/EmergeAdapt/caseblocks_api"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.15"
38
+ s.summary = "Ruby wrapper for CaseBlocks API"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
45
+ s.add_development_dependency(%q<pry>, [">= 0"])
46
+ s.add_development_dependency(%q<webmock>, [">= 0"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<bundler>, [">= 0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
51
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
52
+ s.add_development_dependency(%q<growl>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<httparty>, [">= 0"])
55
+ s.add_dependency(%q<pry>, [">= 0"])
56
+ s.add_dependency(%q<webmock>, [">= 0"])
57
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
58
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<bundler>, [">= 0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
62
+ s.add_dependency(%q<growl>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<httparty>, [">= 0"])
66
+ s.add_dependency(%q<pry>, [">= 0"])
67
+ s.add_dependency(%q<webmock>, [">= 0"])
68
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
69
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
70
+ s.add_dependency(%q<bundler>, [">= 0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
72
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
73
+ s.add_dependency(%q<growl>, [">= 0"])
74
+ end
75
+ end
76
+
@@ -0,0 +1,7 @@
1
+ module CaseblocksAPI
2
+ class AuthenticationException < Exception
3
+ def initialize(message)
4
+ puts message
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ require "httparty"
2
+ require "json"
3
+ require "caseblocks_api/authentication_exception"
4
+ require 'pry'
5
+
6
+ module CaseblocksAPI
7
+ class Client
8
+ include HTTParty
9
+
10
+ attr_reader :auth_token
11
+
12
+ headers "Accept" => "application/json"
13
+ headers "Content-Type" => "application/json"
14
+
15
+ def initialize(email, password, url)
16
+ self.class.base_uri url
17
+ result = self.class.post("/tokens", :body => {email: email, password: password}.to_json)
18
+ if result["message"]
19
+ raise CaseblocksAPI::AuthenticationException.new(result["message"])
20
+ else
21
+ @auth_token = result["token"] if result
22
+ self.class.default_params("auth_token" => @auth_token)
23
+ end
24
+ end
25
+
26
+ def create_case(params, case_type=nil)
27
+ if case_type
28
+ case_type_id = get_casetype_id(case_type)
29
+ end
30
+ if case_type_id
31
+ params = params.merge(:case_type_id => case_type_id)
32
+ end
33
+ self.class.post("/case_blocks/cases", :body => {:case => params}.to_json)
34
+ end
35
+
36
+ def get_casetype_id(case_type_name)
37
+ response = self.class.get("/case_blocks/case_types")["case_types"]
38
+ response.each do |case_type|
39
+ if case_type.has_value? case_type_name
40
+ return case_type["id"]
41
+ end
42
+ end
43
+ nil
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CaseblocksApi" do
4
+ describe "When authorising with CaseBlocks" do
5
+ context "when I have an account" do
6
+ it "should respond with and auth token" do
7
+ CaseblocksAPI::Client.stub(:post).and_return({"token" => "some_token"})
8
+ username = "mark@local.me"
9
+ password = "password1"
10
+ caseblocks = CaseblocksAPI::Client.new(username, password, "http://localhost:3000")
11
+ caseblocks.auth_token.should eql "some_token"
12
+ end
13
+ end
14
+
15
+ context "when I don't have an account" do
16
+ it "should raise an error" do
17
+ CaseblocksAPI::Client.stub(:post).and_return({"message" => "You must have an account to do that"})
18
+ lambda { CaseblocksAPI::Client.new("blah@blah.com", "blahblah", "http://localhost:3000")}.should raise_error(CaseblocksAPI::AuthenticationException)
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "when i'm authorised with caseblocks" do
24
+ before do
25
+ CaseblocksAPI::Client.stub(:post).and_return({"token" => "some_token"})
26
+ username = "mark@local.me"
27
+ password = "password1"
28
+ @caseblocks = CaseblocksAPI::Client.new(username, password, "http://localhost:3000")
29
+ end
30
+
31
+ it "should return me the requested case type" do
32
+ @caseblocks.stub(:get_casetype_id).and_return(2)
33
+ case_type = @caseblocks.get_casetype_id("Some Case type")
34
+ case_type.should eql 2
35
+ end
36
+
37
+ it "should let me create a case" do
38
+ CaseblocksAPI::Client.stub(:post).and_return({"token" => "some_token"})
39
+ params = {"title" => "This is a Case!", "due_at" => Time.now + 1000, "owned_by_id" => 1, "owned_by_type" => "CaseBlocks::User"}
40
+ @caseblocks.stub(:create_case).and_return({"case" => {}})
41
+ response = @caseblocks.create_case(params, "Tyre Shopper Order")
42
+ response.should include("case")
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'caseblocks_api'
5
+ #require 'webmock/rspec'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caseblocks_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Provan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70152411718760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70152411718760
25
+ - !ruby/object:Gem::Dependency
26
+ name: pry
27
+ requirement: &70152411731980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70152411731980
36
+ - !ruby/object:Gem::Dependency
37
+ name: webmock
38
+ requirement: &70152411730780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70152411730780
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70152411729420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70152411729420
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &70152411727860 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '3.12'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70152411727860
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70152411726500 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70152411726500
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &70152411725680 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.8.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70152411725680
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-rspec
93
+ requirement: &70152411739800 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70152411739800
102
+ - !ruby/object:Gem::Dependency
103
+ name: growl
104
+ requirement: &70152411737580 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70152411737580
113
+ description:
114
+ email: development@emergeadapt.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files:
118
+ - LICENSE.txt
119
+ - README.rdoc
120
+ files:
121
+ - .document
122
+ - .rspec
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - Guardfile
126
+ - LICENSE.txt
127
+ - README.rdoc
128
+ - Rakefile
129
+ - VERSION
130
+ - caseblocks_api.gemspec
131
+ - lib/caseblocks_api.rb
132
+ - lib/caseblocks_api/authentication_exception.rb
133
+ - spec/caseblocks_api_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: http://github.com/EmergeAdapt/caseblocks_api
136
+ licenses:
137
+ - MIT
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ segments:
149
+ - 0
150
+ hash: 3280697682881866942
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.15
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Ruby wrapper for CaseBlocks API
163
+ test_files: []