zendesk_api 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,8 +5,7 @@ source 'https://rubygems.org'
5
5
 
6
6
  gem "simplecov", :platforms => :ruby_19, :group => :development
7
7
  gem "jruby-openssl", :platforms => :jruby
8
- gem "hashie", :git => "git://github.com/intridea/hashie.git"
9
- gem "multipart-post", :git => "git://github.com/steved555/multipart-post.git"
8
+ gem "multipart-post", :git => "https://github.com/steved555/multipart-post.git"
10
9
  gem "multi_json", :group => :test
11
10
 
12
11
  group :server do
data/Gemfile.lock CHANGED
@@ -1,11 +1,5 @@
1
1
  GIT
2
- remote: git://github.com/intridea/hashie.git
3
- revision: f7adbf6b6e29bfcd3efbc33695fe0e018d62e66e
4
- specs:
5
- hashie (2.0.0.beta)
6
-
7
- GIT
8
- remote: git://github.com/steved555/multipart-post.git
2
+ remote: https://github.com/steved555/multipart-post.git
9
3
  revision: 57c66998c05143a684c13694937c8adfd335cae1
10
4
  specs:
11
5
  multipart-post (1.1.5)
@@ -13,10 +7,10 @@ GIT
13
7
  PATH
14
8
  remote: .
15
9
  specs:
16
- zendesk_api (0.3.2)
10
+ zendesk_api (0.3.3)
17
11
  faraday (>= 0.8.0)
18
12
  faraday_middleware (>= 0.8.7)
19
- hashie
13
+ hashie (~> 2.0.0)
20
14
  inflection
21
15
  json
22
16
  mime-types
@@ -25,24 +19,24 @@ PATH
25
19
  GEM
26
20
  remote: https://rubygems.org/
27
21
  specs:
28
- activemodel (3.2.11)
29
- activesupport (= 3.2.11)
22
+ activemodel (3.2.13)
23
+ activesupport (= 3.2.13)
30
24
  builder (~> 3.0.0)
31
- activesupport (3.2.11)
32
- i18n (~> 0.6)
25
+ activesupport (3.2.13)
26
+ i18n (= 0.6.1)
33
27
  multi_json (~> 1.0)
34
- addressable (2.3.2)
35
- backports (2.8.2)
28
+ addressable (2.3.3)
29
+ backports (3.1.1)
36
30
  bond (0.4.3)
37
31
  bond (0.4.3-java)
38
- bootstrap-sass (2.2.2.0)
32
+ bootstrap-sass (2.3.1.0)
39
33
  sass (~> 3.2)
40
- bouncy-castle-java (1.5.0146.1)
34
+ bouncy-castle-java (1.5.0147)
41
35
  builder (3.0.4)
42
- bump (0.3.9)
43
- chunky_png (1.2.7)
44
- coderay (1.0.8)
45
- coderay_bash (1.0.4)
36
+ bump (0.4.0)
37
+ chunky_png (1.2.8)
38
+ coderay (1.0.9)
39
+ coderay_bash (1.0.5)
46
40
  coderay (>= 1.0)
47
41
  compass (0.12.2)
48
42
  chunky_png (~> 1.2)
@@ -51,54 +45,56 @@ GEM
51
45
  crack (0.3.2)
52
46
  daemons (1.1.9)
53
47
  database_cleaner (0.9.1)
54
- diff-lcs (1.1.3)
55
- eventmachine (1.0.0)
56
- eventmachine (1.0.0-java)
57
- faraday (0.8.6)
48
+ diff-lcs (1.2.2)
49
+ eventmachine (1.0.3)
50
+ eventmachine (1.0.3-java)
51
+ faraday (0.8.7)
58
52
  multipart-post (~> 1.1)
59
53
  faraday_middleware (0.9.0)
60
54
  faraday (>= 0.7.4, < 0.9)
61
55
  fssm (0.2.10)
62
- haml (3.1.7)
56
+ haml (4.0.1)
57
+ tilt
58
+ hashie (2.0.0)
63
59
  i18n (0.6.1)
64
60
  inflection (1.0.0)
65
- jruby-openssl (0.8.2)
66
- bouncy-castle-java (>= 1.5.0146.1)
61
+ jruby-openssl (0.8.7)
62
+ bouncy-castle-java (>= 1.5.0147)
67
63
  json (1.7.7)
68
- mime-types (1.21)
69
- mongoid (3.0.21)
70
- activemodel (~> 3.1)
71
- moped (~> 1.2)
64
+ mime-types (1.22)
65
+ mongoid (3.1.2)
66
+ activemodel (~> 3.2)
67
+ moped (~> 1.4.2)
72
68
  origin (~> 1.0)
73
69
  tzinfo (~> 0.3.22)
74
- moped (1.3.2)
75
- multi_json (1.5.0)
76
- newrelic_rpm (3.5.3.25)
70
+ moped (1.4.5)
71
+ multi_json (1.7.2)
72
+ newrelic_rpm (3.6.0.78)
77
73
  origin (1.0.11)
78
74
  rack (1.5.2)
79
- rack-protection (1.3.2)
75
+ rack-protection (1.5.0)
80
76
  rack
81
77
  rack-ssl-enforcer (0.2.5)
82
78
  rack-test (0.6.2)
83
79
  rack (>= 1.0)
84
- rake (10.0.3)
80
+ rake (10.0.4)
85
81
  redcarpet (2.2.2)
86
82
  ripl (0.7.0)
87
83
  bond (~> 0.4.2)
88
- rspec (2.12.0)
89
- rspec-core (~> 2.12.0)
90
- rspec-expectations (~> 2.12.0)
91
- rspec-mocks (~> 2.12.0)
92
- rspec-core (2.12.2)
93
- rspec-expectations (2.12.1)
94
- diff-lcs (~> 1.1.3)
95
- rspec-mocks (2.12.2)
96
- sass (3.2.5)
84
+ rspec (2.13.0)
85
+ rspec-core (~> 2.13.0)
86
+ rspec-expectations (~> 2.13.0)
87
+ rspec-mocks (~> 2.13.0)
88
+ rspec-core (2.13.1)
89
+ rspec-expectations (2.13.0)
90
+ diff-lcs (>= 1.1.3, < 2.0)
91
+ rspec-mocks (2.13.0)
92
+ sass (3.2.7)
97
93
  simplecov (0.7.1)
98
94
  multi_json (~> 1.0)
99
95
  simplecov-html (~> 0.7.1)
100
96
  simplecov-html (0.7.1)
101
- sinatra (1.3.4)
97
+ sinatra (1.3.6)
102
98
  rack (~> 1.4)
103
99
  rack-protection (~> 1.3)
104
100
  tilt (~> 1.3, >= 1.3.3)
@@ -109,17 +105,17 @@ GEM
109
105
  rack-test
110
106
  sinatra (~> 1.3.0)
111
107
  tilt (~> 1.3)
112
- thin (1.5.0)
108
+ thin (1.5.1)
113
109
  daemons (>= 1.0.9)
114
110
  eventmachine (>= 0.12.6)
115
111
  rack (>= 1.0.0)
116
- tilt (1.3.3)
117
- tzinfo (0.3.35)
112
+ tilt (1.3.6)
113
+ tzinfo (0.3.37)
118
114
  vcr (2.4.0)
119
- webmock (1.9.0)
115
+ webmock (1.9.3)
120
116
  addressable (>= 2.2.7)
121
- crack (>= 0.1.7)
122
- yard (0.8.4.1)
117
+ crack (>= 0.3.2)
118
+ yard (0.8.5.2)
123
119
 
124
120
  PLATFORMS
125
121
  java
@@ -133,7 +129,6 @@ DEPENDENCIES
133
129
  compass
134
130
  database_cleaner
135
131
  haml
136
- hashie!
137
132
  jruby-openssl
138
133
  mongoid
139
134
  multi_json
@@ -149,6 +144,6 @@ DEPENDENCIES
149
144
  sinatra-contrib
150
145
  thin
151
146
  vcr
152
- webmock
147
+ webmock (~> 1.9.0)
153
148
  yard
154
149
  zendesk_api!
@@ -25,6 +25,8 @@ module ZendeskAPI
25
25
  else
26
26
  {self.class.singular_resource_name.to_sym => attributes.changes}
27
27
  end
28
+
29
+ req.body.merge!(@global_params)
28
30
  end
29
31
 
30
32
  @attributes.replace @attributes.deep_merge(@response.body[self.class.singular_resource_name] || {})
@@ -189,10 +191,10 @@ module ZendeskAPI
189
191
 
190
192
  # Updates a resource given the id passed in.
191
193
  # @param [Client] client The {Client} object to be used
192
- # @param [Hash] attributes The attributes to update. Default to {}
194
+ # @param [Hash] attributes The attributes to update. Default to {}
193
195
  def update(client, attributes = {})
194
196
  ZendeskAPI::Client.check_deprecated_namespace_usage attributes, singular_resource_name
195
- resource = new(client, :id => attributes.delete(:id))
197
+ resource = new(client, {:id => attributes.delete(:id), :global => attributes.delete(:global)})
196
198
  resource.attributes.merge!(attributes)
197
199
  resource.save
198
200
  end
@@ -36,7 +36,7 @@ module ZendeskAPI
36
36
 
37
37
  @resource_cache[method] ||= {}
38
38
 
39
- if !options[:reload] && (cached = @resource_cache[method][options.hash])
39
+ if !options.delete(:reload) && (cached = @resource_cache[method][options.hash])
40
40
  cached
41
41
  else
42
42
  @resource_cache[method][options.hash] = ZendeskAPI::Collection.new(self, ZendeskAPI.const_get(ZendeskAPI::Helpers.modulize_string(Inflection.singular(method))), options)
@@ -10,9 +10,10 @@ module ZendeskAPI
10
10
  @client = client
11
11
  end
12
12
 
13
- def on_complete(env)
14
- super(env)
15
- @client.callbacks.each {|c| c.call(env)}
13
+ def call(env)
14
+ @app.call(env).on_complete do |env|
15
+ @client.callbacks.each {|c| c.call(env)}
16
+ end
16
17
  end
17
18
  end
18
19
  end
@@ -8,6 +8,7 @@ module ZendeskAPI
8
8
  class Logger < Faraday::Response::Middleware
9
9
  def initialize(app, logger = nil)
10
10
  super(app)
11
+
11
12
  @logger = logger || begin
12
13
  require 'logger'
13
14
  ::Logger.new(STDOUT)
@@ -17,12 +18,11 @@ module ZendeskAPI
17
18
  def call(env)
18
19
  @logger.info "#{env[:method]} #{env[:url].to_s}"
19
20
  @logger.debug dump_debug(env, :request_headers)
20
- super
21
- end
22
21
 
23
- def on_complete(env)
24
- @logger.info("Status #{env[:status].to_s}")
25
- @logger.debug dump_debug(env, :response_headers)
22
+ @app.call(env).on_complete do |env|
23
+ @logger.info("Status #{env[:status].to_s}")
24
+ @logger.debug dump_debug(env, :response_headers)
25
+ end
26
26
  end
27
27
 
28
28
  private
@@ -8,9 +8,9 @@ module ZendeskAPI
8
8
  # @private
9
9
  class ParseIsoDates < Faraday::Response::Middleware
10
10
  def call(env)
11
- response = @app.call(env)
12
- parse_dates! response.env[:body]
13
- response
11
+ @app.call(env).on_complete do |env|
12
+ parse_dates!(env[:body])
13
+ end
14
14
  end
15
15
 
16
16
  private
@@ -57,6 +57,7 @@ module ZendeskAPI
57
57
  def initialize(client, attributes = {})
58
58
  raise "Expected a Hash for attributes, got #{attributes.inspect}" unless attributes.is_a?(Hash)
59
59
  @association = attributes.delete(:association) || Association.new(:class => self.class)
60
+ @global_params = attributes.delete(:global) || {}
60
61
  @client = client
61
62
  @attributes = ZendeskAPI::Trackie.new(attributes)
62
63
 
@@ -21,7 +21,15 @@ module ZendeskAPI
21
21
  module InstanceMethods
22
22
  def clear_changes
23
23
  each do |k, v|
24
- v.clear_changes if v.respond_to?(:clear_changes)
24
+ if v.respond_to?(:clear_changes)
25
+ v.clear_changes
26
+ elsif v.is_a?(Array)
27
+ v.each do |val|
28
+ if val.respond_to?(:clear_changes)
29
+ val.clear_changes
30
+ end
31
+ end
32
+ end
25
33
  end
26
34
 
27
35
  changes.clear
@@ -59,6 +67,8 @@ module ZendeskAPI
59
67
  each do |k, v|
60
68
  if v.respond_to?(:changed?) && v.changed?
61
69
  changes[k] = v.changes
70
+ elsif v.is_a?(Array) && v.any? {|val| val.respond_to?(:changed?) && val.changed?}
71
+ changes[k] = v
62
72
  end
63
73
  end
64
74
  end
@@ -71,6 +81,7 @@ module ZendeskAPI
71
81
  changes.key?(key)
72
82
  end
73
83
  end
84
+
74
85
  alias :dirty? :changed?
75
86
  end
76
87
  end
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -165,6 +165,15 @@ describe ZendeskAPI::Client do
165
165
  subject.search(:query => 'abc').should_not == subject.search(:query => '123')
166
166
  end
167
167
 
168
+ it "should not cache calls with :reload => true options" do
169
+ subject.search(:query => 'abc').should_not == subject.search(:query => 'abc', :reload => true)
170
+ end
171
+
172
+ it "should not pass reload to the underlying collection" do
173
+ collection = subject.search(:query => 'abc', :reload => true)
174
+ collection.options.key?(:reload).should be_false
175
+ end
176
+
168
177
  it "should cache calls with the same options" do
169
178
  subject.search(:query => 'abc').should == subject.search(:query => 'abc')
170
179
  end
@@ -1,6 +1,15 @@
1
1
  require 'core/spec_helper'
2
2
 
3
3
  describe ZendeskAPI::Resource do
4
+ context "initialize" do
5
+ context "with :global as part of attributes" do
6
+ it "should set @global_params" do
7
+ resource = ZendeskAPI::TestResource.new(client, { :global => { :something => 'hey' }})
8
+ resource.instance_variable_get(:@global_params).should == { :something => 'hey' }
9
+ end
10
+ end
11
+ end
12
+
4
13
  context "#update" do
5
14
  context "class method" do
6
15
  let(:id) { 1 }
@@ -14,6 +23,16 @@ describe ZendeskAPI::Resource do
14
23
  subject.update(client, :id => id, :test => :hello).should be_true
15
24
  end
16
25
 
26
+ context "with global params" do
27
+ before(:each) do
28
+ stub_json_request(:put, %r{test_resources/#{id}}).with(:body => json({ :test_resource => { :test => :hello }, :something => "something"}))
29
+ end
30
+
31
+ it "should return instance of resource" do
32
+ subject.update(client, :id => id, :test => :hello, :global => {:something => "something"}).should be_true
33
+ end
34
+ end
35
+
17
36
  context "with client error" do
18
37
  before(:each) do
19
38
  stub_request(:put, %r{test_resources/#{id}}).to_return(:status => 500)
@@ -55,6 +55,50 @@ describe ZendeskAPI::Trackie do
55
55
  end
56
56
  end
57
57
 
58
+ =begin TODO
59
+ context "nested arrays" do
60
+ before(:each) do
61
+ subject[:key] = []
62
+ subject.clear_changes
63
+ subject[:key] << :test
64
+ end
65
+
66
+ it "should include changes from nested array" do
67
+ subject.changes[:key].should == [:test]
68
+ end
69
+
70
+ specify "subject should be changed" do
71
+ subject.changed?.should be_true
72
+ end
73
+ end
74
+ =end
75
+
76
+ context "nested hashes in arrays" do
77
+ before(:each) do
78
+ subject[:key] = [ZendeskAPI::Trackie.new]
79
+ subject.clear_changes
80
+ subject[:key].first[:test] = true
81
+ end
82
+
83
+ it "should include changes from nested array" do
84
+ subject.changes[:key].first[:test].should be_true
85
+ end
86
+
87
+ specify "subject should be changed" do
88
+ subject.changed?.should be_true
89
+ end
90
+
91
+ context "clearing" do
92
+ before(:each) do
93
+ subject.clear_changes
94
+ end
95
+
96
+ it "should not have any changes" do
97
+ subject.changes.should be_empty
98
+ end
99
+ end
100
+ end
101
+
58
102
  describe "#size" do
59
103
  before do
60
104
  subject[:size] = 42
@@ -82,10 +82,5 @@ module ZendeskAPI
82
82
  @organization ||= current_user.organization
83
83
  end
84
84
  end
85
-
86
- # Global default options, overwritten if using under
87
- def default_options
88
- {}
89
- end
90
85
  end
91
86
  end
@@ -10,7 +10,7 @@ describe ZendeskAPI::Collection do
10
10
  ZendeskAPI::Collection.new(client, ZendeskAPI::User)
11
11
  end
12
12
 
13
- before(:all) do
13
+ before(:each) do
14
14
  VCR.use_cassette('collection_fetch_users') do
15
15
  subject.per_page(1).page(2)
16
16
  subject.fetch(true)
@@ -41,15 +41,15 @@ describe ZendeskAPI::Collection do
41
41
  before(:each) { subject.per_page(1).page(2) }
42
42
 
43
43
  it "should increase page option and not call fetch" do
44
- subject.next.should == 3
44
+ subject.next.should == 3
45
45
  end
46
46
 
47
47
  it "should decrease page option and not call fetch" do
48
- subject.prev.should == 1
48
+ subject.prev.should == 1
49
49
  end
50
50
 
51
51
  context "with page == 1" do
52
- before do
52
+ before do
53
53
  subject.page(1)
54
54
  subject.clear_cache
55
55
  subject.should_not_receive(:fetch)
@@ -14,7 +14,9 @@ describe ZendeskAPI::Group, :delete_after do
14
14
  context "with a membership" do
15
15
  before(:each) do
16
16
  VCR.use_cassette("read_ZendeskAPI::User_groups_create") do
17
- @object = described_class.create!(client, valid_attributes.merge(default_options))
17
+ attrs = valid_attributes
18
+ attrs.merge!(@default_options) if @default_options
19
+ @object = described_class.create!(client, attrs)
18
20
  @membership = agent.group_memberships.create(:group_id => @object.id, :user_id => agent.id)
19
21
  end
20
22
  end
@@ -76,7 +76,7 @@ describe ZendeskAPI::Ticket do
76
76
 
77
77
  it "can upload while creating" do
78
78
  VCR.use_cassette("ticket_inline_uploads") do
79
- ticket = ZendeskAPI::Ticket.new(client, valid_attributes.merge(default_options))
79
+ ticket = ZendeskAPI::Ticket.new(client, valid_attributes)
80
80
  ticket.comment.uploads << "spec/fixtures/Argentina.gif"
81
81
  ticket.comment.uploads << File.new("spec/fixtures/Argentina.gif")
82
82
 
@@ -88,7 +88,7 @@ describe ZendeskAPI::Ticket do
88
88
 
89
89
  it "can comment while creating" do
90
90
  VCR.use_cassette("ticket_inline_comments") do
91
- ticket = ZendeskAPI::Ticket.new(client, valid_attributes.merge(default_options))
91
+ ticket = ZendeskAPI::Ticket.new(client, valid_attributes)
92
92
  ticket.comment = ZendeskAPI::Ticket::Comment.new(client, :value => "My comment", :public => false)
93
93
  ticket.save!
94
94
 
@@ -1,7 +1,14 @@
1
1
  module ResourceMacros
2
+ def self.extended(klass)
3
+ klass.define_method(:default_options) {{}}
4
+ end
5
+
2
6
  def under(object, &blk)
3
7
  context "under a #{object.class.singular_resource_name}" do
4
- let(:default_options) { { "#{object.class.singular_resource_name}_id" => object.id } }
8
+ define_method(:default_options) do
9
+ { "#{object.class.singular_resource_name}_id" => object.id }
10
+ end
11
+
5
12
  instance_eval(&blk)
6
13
  end
7
14
  end
data/zendesk_api.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rake"
23
23
  s.add_development_dependency "rspec"
24
24
  s.add_development_dependency "vcr"
25
- s.add_development_dependency "webmock"
25
+ s.add_development_dependency "webmock", "~> 1.9.0"
26
26
  s.add_development_dependency "yard"
27
27
 
28
28
  # Optional. Only used for uploads testing.
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
 
31
31
  s.add_runtime_dependency "faraday", ">= 0.8.0"
32
32
  s.add_runtime_dependency "faraday_middleware", ">= 0.8.7"
33
- s.add_runtime_dependency "hashie"
33
+ s.add_runtime_dependency "hashie", "~> 2.0.0"
34
34
  s.add_runtime_dependency "inflection"
35
35
  s.add_runtime_dependency "json"
36
36
  s.add_runtime_dependency "mime-types"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-11 00:00:00.000000000 Z
13
+ date: 2013-04-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bump
@@ -81,17 +81,17 @@ dependencies:
81
81
  requirement: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
84
- - - ! '>='
84
+ - - ~>
85
85
  - !ruby/object:Gem::Version
86
- version: '0'
86
+ version: 1.9.0
87
87
  type: :development
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
92
- - - ! '>='
92
+ - - ~>
93
93
  - !ruby/object:Gem::Version
94
- version: '0'
94
+ version: 1.9.0
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: yard
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -145,17 +145,17 @@ dependencies:
145
145
  requirement: !ruby/object:Gem::Requirement
146
146
  none: false
147
147
  requirements:
148
- - - ! '>='
148
+ - - ~>
149
149
  - !ruby/object:Gem::Version
150
- version: '0'
150
+ version: 2.0.0
151
151
  type: :runtime
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
154
154
  none: false
155
155
  requirements:
156
- - - ! '>='
156
+ - - ~>
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: 2.0.0
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: inflection
161
161
  requirement: !ruby/object:Gem::Requirement