zendesk_api 0.1.1 → 0.1.2
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.
- data/Gemfile.lock +2 -2
- data/lib/zendesk_api/middleware/request/upload.rb +12 -3
- data/lib/zendesk_api/version.rb +1 -1
- data/spec/middleware/request/upload_spec.rb +51 -0
- data/zendesk_api.gemspec +5 -2
- metadata +4 -3
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zendesk_api (0.1.
|
4
|
+
zendesk_api (0.1.2)
|
5
5
|
faraday (>= 0.8.0)
|
6
6
|
faraday_middleware (>= 0.8.7)
|
7
7
|
hashie
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
addressable (2.2.8)
|
17
17
|
crack (0.3.1)
|
18
18
|
diff-lcs (1.1.3)
|
19
|
-
faraday (0.8.
|
19
|
+
faraday (0.8.2)
|
20
20
|
multipart-post (~> 1.1)
|
21
21
|
faraday_middleware (0.8.8)
|
22
22
|
faraday (>= 0.7.4, < 0.9)
|
@@ -29,12 +29,16 @@ module ZendeskAPI
|
|
29
29
|
end
|
30
30
|
|
31
31
|
case file
|
32
|
-
when File
|
32
|
+
when File, Tempfile
|
33
33
|
path = file.path
|
34
34
|
when String
|
35
35
|
path = file
|
36
36
|
else
|
37
|
-
|
37
|
+
if defined?(ActionDispatch) && file.is_a?(ActionDispatch::Http::UploadedFile)
|
38
|
+
path = file.tempfile.path
|
39
|
+
else
|
40
|
+
warn "WARNING: Passed invalid filename #{file} of type #{file.class} to upload"
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
if path
|
@@ -45,7 +49,12 @@ module ZendeskAPI
|
|
45
49
|
|
46
50
|
mime_type = MIME::Types.type_for(path).first || "application/octet-stream"
|
47
51
|
|
48
|
-
hash[:filename] ||=
|
52
|
+
hash[:filename] ||= if file.respond_to?(:original_filename)
|
53
|
+
file.original_filename
|
54
|
+
else
|
55
|
+
File.basename(path)
|
56
|
+
end
|
57
|
+
|
49
58
|
hash[:uploaded_data] = Faraday::UploadIO.new(path, mime_type)
|
50
59
|
end
|
51
60
|
end
|
data/lib/zendesk_api/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
describe ZendeskAPI::Middleware::Request::Upload do
|
4
5
|
subject { ZendeskAPI::Middleware::Request::Upload.new(lambda {|env| env}) }
|
@@ -44,6 +45,56 @@ describe ZendeskAPI::Middleware::Request::Upload do
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
begin
|
49
|
+
require 'action_dispatch'
|
50
|
+
rescue LoadError
|
51
|
+
warn "Could not load ActionDispatch; not running ActionDispatch::Http::UploadedFile tests"
|
52
|
+
end
|
53
|
+
|
54
|
+
if defined?(ActionDispatch)
|
55
|
+
class String
|
56
|
+
def encoding_aware?; false; end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with an ActionDispatch::Http::UploadedFile" do
|
60
|
+
before(:each) do
|
61
|
+
@upload = ActionDispatch::Http::UploadedFile.new(:filename => "hello", :tempfile => Tempfile.new(filename))
|
62
|
+
@env = subject.call(:body => { :file => @upload })
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should convert file string to UploadIO" do
|
66
|
+
@env[:body][:uploaded_data].should be_instance_of(Faraday::UploadIO)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should remove file string" do
|
70
|
+
@env[:body][:file].should be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should add filename if none exist" do
|
74
|
+
@env[:body][:filename].should == "hello"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with a Tempfile" do
|
80
|
+
before(:each) do
|
81
|
+
@tempfile = Tempfile.new(filename)
|
82
|
+
@env = subject.call(:body => { :file => @tempfile })
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should convert file string to UploadIO" do
|
86
|
+
@env[:body][:uploaded_data].should be_instance_of(Faraday::UploadIO)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should remove file string" do
|
90
|
+
@env[:body][:file].should be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should add filename if none exist" do
|
94
|
+
@env[:body][:filename].should == File.basename(@tempfile.path)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
47
98
|
context "with file instance" do
|
48
99
|
context "top-level" do
|
49
100
|
before(:each) do
|
data/zendesk_api.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.name = "zendesk_api"
|
9
9
|
s.version = ZendeskAPI::VERSION
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
|
-
s.authors = ["Steven Davidovitz"]
|
12
|
-
s.email = ["
|
11
|
+
s.authors = ["Steven Davidovitz", "Michael Grosser"]
|
12
|
+
s.email = ["support@zendesk.com"]
|
13
13
|
s.homepage = "http://developer.zendesk.com"
|
14
14
|
s.summary = %q{Zendesk REST API Client}
|
15
15
|
s.description = %q{Ruby wrapper for the REST API at http://www.zendesk.com. Documentation at http://developer.zendesk.com.}
|
@@ -24,6 +24,9 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "rake"
|
25
25
|
s.add_development_dependency "yard"
|
26
26
|
|
27
|
+
# Optional. Only used for uploads testing.
|
28
|
+
# s.add_development_dependency "actionpack"
|
29
|
+
|
27
30
|
s.add_runtime_dependency "faraday", ">= 0.8.0"
|
28
31
|
s.add_runtime_dependency "faraday_middleware", ">= 0.8.7"
|
29
32
|
s.add_runtime_dependency "hashie"
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Steven Davidovitz
|
9
|
+
- Michael Grosser
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
13
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rspec
|
@@ -206,7 +207,7 @@ dependencies:
|
|
206
207
|
description: Ruby wrapper for the REST API at http://www.zendesk.com. Documentation
|
207
208
|
at http://developer.zendesk.com.
|
208
209
|
email:
|
209
|
-
-
|
210
|
+
- support@zendesk.com
|
210
211
|
executables: []
|
211
212
|
extensions: []
|
212
213
|
extra_rdoc_files: []
|