ink_file_picker 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b9c7875362ff6bf4c1184114dcd2c1481ac4620
4
- data.tar.gz: 4c58dbe3e7a6677f38bc9149f8240c1352de344b
3
+ metadata.gz: b7a681af38820d24f5944958571caa2ec6e9a2a2
4
+ data.tar.gz: c689b7e0f95090e1563c3aa10de8bcd85e3e240b
5
5
  SHA512:
6
- metadata.gz: a5e696624475b6c20b69eea7fc335dd6787951c5be8c63160dd641a570fed579bc625ec8154a449ae608204f2a834ea3c457ffaecd5bd96e273486e366c76e5a
7
- data.tar.gz: fba1614dea4bf46e59cab2574e0713cc4947d79471c9a364f2fd72d911bf7784684236fbe81490e69c87365587b31bddeecba0a9698f52accb2b808bc91680c8
6
+ metadata.gz: 006cda13b071eaf270d6c99dde3423e21cc3506f297cdbbc44f66dfdd1478664633f10e6a634b6e15aeee76abea4571cc117bd9365d994864307c6e9ac581a84
7
+ data.tar.gz: ac22138a939849a2521d635178fdeeeef8b462290db9427bb039bcb1d63ddf8928875b05b9df1b88c96c4bef520b081e3858055a99013434a12fe71dfdf2519f
@@ -0,0 +1,13 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.2
6
+ - ruby-head
7
+ - jruby-19mode
8
+ - jruby
9
+ - jruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: jruby-head
13
+ - rvm: ruby-head
@@ -0,0 +1,13 @@
1
+ ## 0.0.3
2
+ * Raise UnexpectedResponseError if we receive a 200 OK, but response body is neither "success", nor valid JSON.
3
+ This may happen if you ask File Picker to download a URL, but the server for the given URL fails to respond
4
+ within five(?) seconds. We will then have a 200 OK, but the body will reveal the timeout error in text and
5
+ the UnexpectedResponseError is raised. Other download errors may also be in the response, for instance
6
+ "Invalid response when trying to read from `http://some.url.com/here.jpg`.
7
+
8
+
9
+ ## 0.0.2
10
+ * You can call to_hash on response objects.
11
+
12
+ ## 0.0.1
13
+ * First release. Main functionality like store_url, store_file, remove, stat etc.
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Ruby API client for Ink File Picker (known as filepicker.io).
4
4
 
5
+ [![Build Status](https://travis-ci.org/Skalar/ink_file_picker.svg?branch=master)](https://travis-ci.org/Skalar/ink_file_picker)
5
6
 
6
7
 
7
8
  ## Installation
@@ -51,8 +52,9 @@ url = client.convert_url url_or_handle_name, w: 100, h: 100
51
52
  url = client.convert_url url_or_handle_name, {w: 100, h: 100}, expiry: 10.minutes.from_now.to_i
52
53
 
53
54
  # Adds policy and signature, if secret given when client was created.
55
+ get_params = {} # Get params we'll be adding to the request.
54
56
  url = client.retrieve_url url_or_handle_name
55
- url = client.retrieve_url url_or_handle_name, expiry: 10.minutes.from_now.to_i
57
+ url = client.retrieve_url url_or_handle_name, get_params, expiry: 10.minutes.from_now.to_i
56
58
 
57
59
 
58
60
  # Get simple stat on a file, like the Javascript client
@@ -66,6 +68,10 @@ dimentions = client.stat url_or_handle_name, {width: true, height: true}
66
68
  When making requests to the API errors may occur. `InkFilePicker::ClientError` or `InkFilePicker::ServerError` will
67
69
  be raised if we are getting 4xx or 5xx responses back from File Picker. All errors inherits from `InkFilePicker::Error`.
68
70
 
71
+ We may also fail with a `InkFilePicker::UnexpectedResponseError`. This happens when for instance you ask File Picker
72
+ to download a URL, but the server for the given URL fails to respond within five(?) seconds. We will then get a 200 OK,
73
+ but the body will reveal the timeout error in text and the UnexpectedResponseError is raised.
74
+ Other download errors may also be in the response, for instance "Invalid response when trying to read from `http://some.url.com/here.jpg`.
69
75
 
70
76
  ## Contributing
71
77
 
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task default: :spec
@@ -170,7 +170,9 @@ module InkFilePicker
170
170
  def wrap_response_or_fail_unless_success!(response)
171
171
  case response.status
172
172
  when 200...300
173
- Response.new response
173
+ Response.new(response).tap do |wrapped_response|
174
+ fail UnexpectedResponseError, response.body unless wrapped_response.valid?
175
+ end
174
176
  when 400...500
175
177
  fail ClientError.new response.body, response
176
178
  when 500...600
@@ -33,4 +33,22 @@ module InkFilePicker
33
33
  class ClientError < Error
34
34
  include ErrorWithOriginal
35
35
  end
36
+
37
+ # Public: When FilePicker returns 200 OK http status, but body is unexpected.
38
+ #
39
+ # These errors mainly comes from http status code 200, but at the same time the
40
+ # body is not 'success' neither a parsable JSON string.
41
+ #
42
+ # This seem to happen, for instance when you ask File Picker to store a URL
43
+ # and the remote server we want to download files from takes more than 5 seconds
44
+ # before it starts sending data. At this point FilePicker returns 200 OK, with a
45
+ # body like:
46
+ # "[uuid=D93D897C42254BFA] Invalid URL file http://www.example.com/slow-response.jpg - timeout"
47
+ #
48
+ # In stead of returning this response and get a JSON::ParserError down the road
49
+ # we fail as soon as we see something like this.
50
+ #
51
+ # As of writing this I don't know if this is the best solution to the situation.
52
+ class UnexpectedResponseError < Error
53
+ end
36
54
  end
@@ -29,5 +29,12 @@ module InkFilePicker
29
29
  def parsed_body
30
30
  @parsed_body ||= JSON.parse http_response.body
31
31
  end
32
+
33
+ def valid?
34
+ body == 'success' ||
35
+ parsed_body
36
+ rescue JSON::ParserError
37
+ false
38
+ end
32
39
  end
33
40
  end
@@ -1,3 +1,3 @@
1
1
  module InkFilePicker
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -72,6 +72,23 @@ describe InkFilePicker::Client do
72
72
  expect { subject.store_url url, expiry: 1394363896 }.to raise_error InkFilePicker::ClientError
73
73
  end
74
74
 
75
+ it "handles timeout error on remote server correctly" do
76
+ response_body = "[uuid=D93D897C42254BFB] Invalid URL file http://vp.viseno.no/vp_image.php?type=create_project_letter_head&id=1378387&ts=20140413133631&source_mediatype_code=shoebox_hq&format=jpeg&resolution=300&relative=true&scale=bestfit - timeout"
77
+
78
+ stubs = Faraday::Adapter::Test::Stubs.new do |stub|
79
+ store_path = subject.configuration.store_path + '?key=key&policy=eyJleHBpcnkiOjEzOTQzNjM4OTYsImNhbGwiOiJzdG9yZSJ9&signature=60cb43bb945543d7fdbd2662ae21d5c53e28529720263619cfebc3509e820807'
80
+ stub.post(store_path, {url: url}) { [200, {}, response_body] }
81
+ end
82
+
83
+ stubbed_connection = Faraday.new do |builder|
84
+ builder.adapter :test, stubs
85
+ end
86
+
87
+ subject.stub(:http_connection).and_return stubbed_connection
88
+
89
+ expect { subject.store_url url, expiry: 1394363896 }.to raise_error InkFilePicker::UnexpectedResponseError
90
+ end
91
+
75
92
  it "handles server errors correctly" do
76
93
  stubs = Faraday::Adapter::Test::Stubs.new do |stub|
77
94
  store_path = subject.configuration.store_path + '?key=key&policy=eyJleHBpcnkiOjEzOTQzNjM4OTYsImNhbGwiOiJzdG9yZSJ9&signature=60cb43bb945543d7fdbd2662ae21d5c53e28529720263619cfebc3509e820807'
@@ -37,4 +37,20 @@ describe InkFilePicker::Response do
37
37
  expect(subject.public_send name).to eq 'an answer'
38
38
  end
39
39
  end
40
+
41
+ describe "#valid?" do
42
+ context "valid JSON as body" do
43
+ it "is true" do
44
+ expect(subject).to be_valid
45
+ end
46
+ end
47
+
48
+ context "invalid JSON as body" do
49
+ let(:http_response_body) { '[uuid=D93D897C42254BFB] Invalid URL file http://vp.viseno.no/vp_image.php?type=create_project_letter_head&id=1378387&ts=20140413133631&source_mediatype_code=shoebox_hq&format=jpeg&resolution=300&relative=true&scale=bestfit - timeout' }
50
+
51
+ it "is false" do
52
+ expect(subject).to_not be_valid
53
+ end
54
+ end
55
+ end
40
56
  end
metadata CHANGED
@@ -1,89 +1,89 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ink_file_picker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorbjørn Hermansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.14
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.2.14
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: 0.9.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ~>
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.9.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ~>
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '1.5'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ~>
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.5'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - '>='
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ~>
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: 2.14.1
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ~>
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 2.14.1
89
89
  description:
@@ -93,7 +93,9 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - .gitignore
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - CHANGELOG.md
97
99
  - Gemfile
98
100
  - LICENSE.txt
99
101
  - README.md
@@ -127,17 +129,17 @@ require_paths:
127
129
  - lib
128
130
  required_ruby_version: !ruby/object:Gem::Requirement
129
131
  requirements:
130
- - - '>='
132
+ - - ">="
131
133
  - !ruby/object:Gem::Version
132
134
  version: '0'
133
135
  required_rubygems_version: !ruby/object:Gem::Requirement
134
136
  requirements:
135
- - - '>='
137
+ - - ">="
136
138
  - !ruby/object:Gem::Version
137
139
  version: '0'
138
140
  requirements: []
139
141
  rubyforge_project:
140
- rubygems_version: 2.0.0
142
+ rubygems_version: 2.2.2
141
143
  signing_key:
142
144
  specification_version: 4
143
145
  summary: Client for Ink File Picker