caseblocks_api 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -6,12 +6,6 @@ source "http://rubygems.org"
6
6
  gem 'httparty'
7
7
  gem 'activesupport'
8
8
 
9
- group :development, :test do
10
- gem 'pry'
11
- gem 'webmock'
12
- gem 'rspec-given'
13
- end
14
-
15
9
  # Add dependencies to develop your gem here.
16
10
  # Include everything needed to run rake, tests, features, etc.
17
11
  group :development do
@@ -20,4 +14,7 @@ group :development do
20
14
  gem "bundler"
21
15
  gem "jeweler", "~> 1.8.4"
22
16
  gem 'guard-rspec'
17
+ gem 'pry'
18
+ gem 'webmock'
19
+ gem 'rspec-given'
23
20
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "caseblocks_api"
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Provan"]
12
- s.date = "2012-10-21"
12
+ s.date = "2012-11-06"
13
13
  s.email = "development@emergeadapt.com"
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -50,37 +50,37 @@ Gem::Specification.new do |s|
50
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
51
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
52
52
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
53
- s.add_development_dependency(%q<pry>, [">= 0"])
54
- s.add_development_dependency(%q<webmock>, [">= 0"])
55
- s.add_development_dependency(%q<rspec-given>, [">= 0"])
56
53
  s.add_development_dependency(%q<rspec>, ["~> 2.11"])
57
54
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
58
55
  s.add_development_dependency(%q<bundler>, [">= 0"])
59
56
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
60
57
  s.add_development_dependency(%q<guard-rspec>, [">= 0"])
58
+ s.add_development_dependency(%q<pry>, [">= 0"])
59
+ s.add_development_dependency(%q<webmock>, [">= 0"])
60
+ s.add_development_dependency(%q<rspec-given>, [">= 0"])
61
61
  else
62
62
  s.add_dependency(%q<httparty>, [">= 0"])
63
63
  s.add_dependency(%q<activesupport>, [">= 0"])
64
- s.add_dependency(%q<pry>, [">= 0"])
65
- s.add_dependency(%q<webmock>, [">= 0"])
66
- s.add_dependency(%q<rspec-given>, [">= 0"])
67
64
  s.add_dependency(%q<rspec>, ["~> 2.11"])
68
65
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
69
66
  s.add_dependency(%q<bundler>, [">= 0"])
70
67
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
71
68
  s.add_dependency(%q<guard-rspec>, [">= 0"])
69
+ s.add_dependency(%q<pry>, [">= 0"])
70
+ s.add_dependency(%q<webmock>, [">= 0"])
71
+ s.add_dependency(%q<rspec-given>, [">= 0"])
72
72
  end
73
73
  else
74
74
  s.add_dependency(%q<httparty>, [">= 0"])
75
75
  s.add_dependency(%q<activesupport>, [">= 0"])
76
- s.add_dependency(%q<pry>, [">= 0"])
77
- s.add_dependency(%q<webmock>, [">= 0"])
78
- s.add_dependency(%q<rspec-given>, [">= 0"])
79
76
  s.add_dependency(%q<rspec>, ["~> 2.11"])
80
77
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
81
78
  s.add_dependency(%q<bundler>, [">= 0"])
82
79
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
83
80
  s.add_dependency(%q<guard-rspec>, [">= 0"])
81
+ s.add_dependency(%q<pry>, [">= 0"])
82
+ s.add_dependency(%q<webmock>, [">= 0"])
83
+ s.add_dependency(%q<rspec-given>, [">= 0"])
84
84
  end
85
85
  end
86
86
 
@@ -28,24 +28,25 @@ module CaseblocksAPI
28
28
  end
29
29
 
30
30
  def create_case(params, case_type=nil)
31
- if case_type
32
- case_type_id = get_casetype_id(case_type)
33
- end
34
- if case_type_id
35
- params = params.merge(:case_type_id => case_type_id)
36
- end
31
+ params.merge!(:case_type_id => fetch_case_type_id(case_type))
37
32
  self.class.post("/case_blocks/cases", :body => {:case => params}.to_json)
38
33
  end
39
34
 
40
- def get_casetype_id(case_type_name)
41
- response = self.class.get("/case_blocks/case_types")["case_types"]
42
- response.each do |case_type|
43
- if case_type.has_value? case_type_name
44
- return case_type["id"]
45
- end
46
- end
47
- nil
48
- end
35
+ private
36
+
37
+ def fetch_case_type_id(case_type_name)
38
+ case_types[case_type_name] || find_case_type_by_name(case_type_name)
39
+ end
40
+
41
+ def find_case_type_by_name(case_type_name)
42
+ @case_types = self.class.get("/case_blocks/case_types")["case_types"]
43
+ case_type = @case_types.select { |k| k.has_key? case_type_name }
44
+ return case_type.first[case_type_name]["id"] unless case_type.nil?
45
+ end
46
+
47
+ def case_types
48
+ @case_types ||= {}
49
+ end
49
50
 
50
51
  end
51
52
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe "CaseblocksApi" do
3
+ describe "CaseblocksAPI" do
4
4
  describe "When authorising with CaseBlocks" do
5
5
  context "when I have an account" do
6
6
  it "should respond with and auth token" do
@@ -20,26 +20,16 @@ describe "CaseblocksApi" do
20
20
  end
21
21
  end
22
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
23
+ describe "creating a case" do
24
+ let(:caseblocks_client) { CaseblocksAPI::Client.new("username", "password", "http://example.com") }
36
25
 
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")
26
+ it "should look for the case type id" do
27
+ stub_request(:post, "http://example.com/tokens?auth_token=some_token")
28
+ CaseblocksAPI::Client.stub(:get).and_return({"case_types" => [ {'some_case' => {"id" => 1}} ]})
29
+ stub = stub_request(:post, "example.com/case_blocks/cases?auth_token=")
30
+ .with({body: { 'case' => {'my' => 'params', 'case_type_id' => 1}}.to_json })
31
+ caseblocks_client.create_case({'my' => 'params'}, 'some_case')
32
+ stub.should have_been_made.times(1)
43
33
  end
44
34
  end
45
35
  end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'rspec'
2
2
  require 'rspec/given'
3
3
  require 'pry'
4
4
  require 'caseblocks_api'
5
+ require 'webmock/rspec'
5
6
 
6
7
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caseblocks_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-21 00:00:00.000000000 Z
12
+ date: 2012-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -44,39 +44,39 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: pry
47
+ name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '2.11'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.11'
62
62
  - !ruby/object:Gem::Dependency
63
- name: webmock
63
+ name: rdoc
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '3.12'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: '3.12'
78
78
  - !ruby/object:Gem::Dependency
79
- name: rspec-given
79
+ name: bundler
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -92,13 +92,13 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: rspec
95
+ name: jeweler
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: '2.11'
101
+ version: 1.8.4
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,25 +106,25 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '2.11'
109
+ version: 1.8.4
110
110
  - !ruby/object:Gem::Dependency
111
- name: rdoc
111
+ name: guard-rspec
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
- - - ~>
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
- version: '3.12'
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  none: false
122
122
  requirements:
123
- - - ~>
123
+ - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
- version: '3.12'
125
+ version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: bundler
127
+ name: pry
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -140,23 +140,23 @@ dependencies:
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
- name: jeweler
143
+ name: webmock
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  none: false
146
146
  requirements:
147
- - - ~>
147
+ - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
- version: 1.8.4
149
+ version: '0'
150
150
  type: :development
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
155
- - - ~>
155
+ - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
- version: 1.8.4
157
+ version: '0'
158
158
  - !ruby/object:Gem::Dependency
159
- name: guard-rspec
159
+ name: rspec-given
160
160
  requirement: !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
@@ -215,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  segments:
217
217
  - 0
218
- hash: -4066504400286969574
218
+ hash: 415753869784523730
219
219
  required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  none: false
221
221
  requirements: