zendesk_api 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- zendesk_api (1.0.5)
10
+ zendesk_api (1.0.6)
11
11
  faraday (>= 0.8.0)
12
12
  faraday_middleware (>= 0.8.7)
13
13
  hashie (>= 1.2)
data/Readme.md CHANGED
@@ -98,6 +98,7 @@ Another way is to use the instance methods under client.
98
98
  ```ruby
99
99
  client.tickets.first
100
100
  client.tickets.find(:id => 1)
101
+ client.tickets.build(:subject => "Test Ticket")
101
102
  client.tickets.create(:subject => "Test Ticket", :comment => { :value => "This is a test" }, :submitter_id => client.current_user.id, :priority => "urgent")
102
103
  client.tickets.destroy(:id => 1)
103
104
  ```
@@ -56,7 +56,28 @@ module ZendeskAPI
56
56
  opts = args.last.is_a?(Hash) ? args.pop : {}
57
57
  opts.merge!(:association => @association)
58
58
 
59
- @resource_class.send(deferrable, @client, @options.merge(opts))
59
+ @resource_class.send(deferrable, @client, opts)
60
+ end
61
+ end
62
+
63
+ # Convenience method to build a new resource and
64
+ # add it to the collection. Fetches the collection as well.
65
+ # @param [Hash] options Options or attributes to pass
66
+ def build(opts = {})
67
+ wrap_resource(opts, true).tap do |res|
68
+ self << res
69
+ end
70
+ end
71
+
72
+ # Convenience method to build a new resource and
73
+ # add it to the collection. Fetches the collection as well.
74
+ # @param [Hash] options Options or attributes to pass
75
+ def build!(opts = {})
76
+ wrap_resource(opts, true).tap do |res|
77
+ fetch!
78
+
79
+ # << does a fetch too
80
+ self << res
60
81
  end
61
82
  end
62
83
 
@@ -119,6 +140,7 @@ module ZendeskAPI
119
140
  # @raise [ArgumentError] if the resource doesn't belong in this collection
120
141
  def <<(item)
121
142
  fetch
143
+
122
144
  if item.is_a?(Resource)
123
145
  if item.is_a?(@resource_class)
124
146
  @resources << item
@@ -16,6 +16,7 @@ module ZendeskAPI
16
16
  end
17
17
 
18
18
  def call(env)
19
+ original_env = env.dup
19
20
  response = @app.call(env)
20
21
 
21
22
  if ERROR_CODES.include?(response.env[:status])
@@ -30,7 +31,7 @@ module ZendeskAPI
30
31
 
31
32
  @logger.warn "" if @logger
32
33
 
33
- @app.call(env)
34
+ @app.call(original_env)
34
35
  else
35
36
  response
36
37
  end
@@ -60,8 +60,10 @@ module ZendeskAPI::Server
60
60
  end
61
61
 
62
62
  def map_headers(headers)
63
+ return "" if !headers
64
+
63
65
  headers.map do |k,v|
64
- name = k.split("-").map(&:capitalize).join("-")
66
+ name = k.to_s.split("-").map(&:capitalize).join("-")
65
67
  "#{name}: #{v}"
66
68
  end.join("\n")
67
69
  end
@@ -89,7 +91,7 @@ HTTP/1.1 #{response[:status]}
89
91
  #{map_headers(response[:headers])}
90
92
 
91
93
 
92
- #{CodeRay.scan(MultiJson.dump(response[:body], :pretty => true), :json).span}
94
+ #{CodeRay.scan(JSON.pretty_generate(response[:body]), :json).span}
93
95
  END
94
96
 
95
97
  @user_response_hash = { :status => response[:status], :headers => response[:headers], :body => response[:body] }
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -98,6 +98,18 @@ describe ZendeskAPI::Collection do
98
98
  it "should pass association" do
99
99
  subject.last.association.should == association
100
100
  end
101
+
102
+ it "should #build a resource and add it" do
103
+ resource = subject.build
104
+ subject.should include(resource)
105
+ resource.association.should == subject.association
106
+ end
107
+
108
+ it "should #build! a resource and add it" do
109
+ resource = subject.build!
110
+ subject.should include(resource)
111
+ resource.association.should == subject.association
112
+ end
101
113
  end
102
114
  end
103
115
  end
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: 1.0.5
4
+ version: 1.0.6
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-09-13 00:00:00.000000000 Z
13
+ date: 2013-09-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bump