uploadcare-ruby 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a64d207f7ef4f89a13f68834cea937420cc9f3a8
4
- data.tar.gz: 4dfa8a074d60bc1a37651fb5c3f138799fe38154
3
+ metadata.gz: ad96fa0d1ad6cea7d89b3b1bab8c78b9cf065491
4
+ data.tar.gz: 34783372b519d4b381b915ddcfe95a0e379d69ab
5
5
  SHA512:
6
- metadata.gz: b23740f26de3e0eeffdb832e431f0a4f739c089afb23f6e9d60a880e1ea2cb497e8288684c8abf96ee4a3daeaaeaea571723e18970fe979dbb1fea77dde4c07f
7
- data.tar.gz: 4552d01fa016da894a2ed61e02f4ead93723b65faa76014ba61ef8af673fa20a61203831efe89e1aa552dfc3cdd39c3abe83622ea9ef93ce6f70e274a261f70f
6
+ metadata.gz: 9336a0ae85297a8e41ad81de42438f4590bb5a08aa0fb1766cbc2d48a09df260a2f38f63174b7549f9fad00961306bf38fa29fb69503fe75d79a394f1ef3520b
7
+ data.tar.gz: 7d1caa97fdd3126394ddfa57dfed635ecd4b7c564331e5e92b072b8425d72a4f4a40a1ab2c592e00fd733aa7430733fd0e3d973fb3b404866e11da0d448b65c3
data/.gitignore CHANGED
@@ -3,4 +3,4 @@ Gemfile.lock
3
3
  .ruby-version
4
4
 
5
5
  *.DS_Store
6
- *.gem
6
+ *.gem
@@ -1,13 +1,37 @@
1
- #Changelog
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
2
3
 
3
- ### 1.1.0, 21.03.2017
4
+ The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
6
 
5
- - Deprecated `Uploadcare::Api::File#copy` in favor of `#internal_copy` and `#external_copy`.
6
- - Added to new methods to Uploadcare::Api::File, #internal_copy and #external_copy.
7
+
8
+ ### [1.2.1] - 2018-05-24
9
+
10
+ ### Changed
11
+ - Allow user to override User-Agent header
12
+ - User-Agent format reports gem name, version and environment
13
+
14
+
15
+ ## 1.1.0 - 2017-03-21
16
+
17
+ ### Added
18
+ - Added to new methods to `Uploadcare::Api::File`, `#internal_copy` and `#external_copy`.
7
19
  - Added support of [secure authorization](https://uploadcare.com/documentation/rest/#request) for REST API. It is now used by default (can be overriden in config)
8
- - Fixed middleware names that could break other gems ([#13](https://github.com/uploadcare/uploadcare-ruby/issues/13}).
9
20
 
10
- ### 1.0.6, 30.01.2017
21
+ ### Fixed
22
+ - Fixed middleware names that could break other gems ([#13](https://github.com/uploadcare/uploadcare-ruby/issues/13)).
23
+
24
+ ### Deprecated
25
+ - `Uploadcare::Api::File#copy` in favor of `#internal_copy` and `#external_copy`.
26
+
27
+
28
+ ## 1.0.6 - 2017-01-30
29
+
30
+ ### Added
31
+ - Ruby version and public API key sent via User-Agent header (can be overriden in config)
32
+
33
+ ### Fixed
34
+ - Incorrect dependencies
35
+
11
36
 
12
- - Fixed incorrect dependencies
13
- - Added ruby version and public API key to User-Agent header (can be overriden in config)
37
+ [1.2.1]: https://github.com/uploadcare/uploadcare-ruby/compare/6dde...v1.2.1
@@ -17,6 +17,7 @@ module Uploadcare
17
17
  auth_scheme: :secure
18
18
  }
19
19
 
20
+ warn '[DEPRECATION] `Uploadcare::USER_AGENT` constant is deprecated and will be removed in version 3.0'
20
21
  USER_AGENT = "uploadcare-ruby/#{Gem.ruby_version}/#{Uploadcare::VERSION}"
21
22
 
22
23
 
@@ -25,7 +26,7 @@ module Uploadcare
25
26
  end
26
27
 
27
28
  def self.user_agent(options={})
28
- return options[:user_agent].to_s if options[:user_agent]
29
- [USER_AGENT, options[:public_key]].join('/')
29
+ warn '[DEPRECATION] `Uploadcare::user_agent` method is deprecated and will be removed in version 3.0'
30
+ UserAgent.new.call(options)
30
31
  end
31
32
  end
@@ -10,7 +10,7 @@ module Uploadcare
10
10
  auth_strategy = Auth.strategy(options)
11
11
 
12
12
  frd.headers['Accept'] = "application/vnd.uploadcare-v#{options[:api_version]}+json"
13
- frd.headers['User-Agent'] = Uploadcare::user_agent(options)
13
+ frd.headers['User-Agent'] = UserAgent.new.call(options)
14
14
 
15
15
  # order of middleware matters!
16
16
 
@@ -27,7 +27,6 @@ module Uploadcare
27
27
  frd.adapter :net_http # actually, default adapter, just to be clear
28
28
  end
29
29
  end
30
-
31
30
  end
32
31
  end
33
32
  end
@@ -10,7 +10,7 @@ module Uploadcare
10
10
  frd.request :multipart
11
11
  frd.request :url_encoded
12
12
  frd.adapter :net_http
13
- frd.headers['User-Agent'] = Uploadcare::user_agent(options)
13
+ frd.headers['User-Agent'] = UserAgent.new.call(options)
14
14
 
15
15
  frd.response :uploadcare_raise_error
16
16
  frd.response :uploadcare_parse_json
@@ -18,4 +18,4 @@ module Uploadcare
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -0,0 +1,44 @@
1
+ module Uploadcare
2
+ # Determines User-Agent string either taking it from settings or building
3
+ # in accordance with common Uploadcare format
4
+ #
5
+ class UserAgent
6
+ # @param options [Hash]
7
+ # @option options [String] :user_agent (nil)
8
+ # @option options [String] :public_key (nil)
9
+ # @option options [String] :user_agent_environment (nil)
10
+ # @return [String]
11
+ #
12
+ def call(options)
13
+ return options[:user_agent].to_s if options[:user_agent]
14
+
15
+ user_agent_string(
16
+ options.fetch(:public_key, nil),
17
+ options.fetch(:user_agent_environment, {})
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ def user_agent_string(public_key, extensions)
24
+ format(
25
+ '%<library>s/%<pubkey>s (%<environment>s)',
26
+ library: versioned('UploadcareRuby', Uploadcare::VERSION),
27
+ pubkey: public_key,
28
+ environment: environment_string(extensions)
29
+ )
30
+ end
31
+
32
+ def environment_string(extensions)
33
+ [
34
+ versioned('Ruby', Gem.ruby_version),
35
+ versioned(extensions[:framework_name], extensions[:framework_version]),
36
+ versioned(extensions[:extension_name], extensions[:extension_version])
37
+ ].compact.join('; ')
38
+ end
39
+
40
+ def versioned(name, version = nil)
41
+ name ? [name, version].compact.join('/') : nil
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Uploadcare
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -19,7 +19,7 @@ describe Uploadcare::Connections::ApiConnection do
19
19
  end
20
20
 
21
21
  it 'includes correct User-Agent header' do
22
- expected = Uploadcare::user_agent(settings)
22
+ expected = Uploadcare::UserAgent.new.call(settings)
23
23
  expect(subject['User-Agent']).to eq expected
24
24
  end
25
25
  end
@@ -1,20 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Uploadcare do
4
-
5
4
  describe '::user_agent' do
6
- context "if :user_agent is specified in method's options" do
7
- it "returns it's stringified version" do
8
- expect( Uploadcare.user_agent(user_agent: 123) ).to eq '123'
9
- end
10
- end
5
+ subject(:user_agent) { described_class.user_agent(options) }
6
+ let(:options) { {user_agent: 'user/agent'} }
7
+ let(:user_agent_builder) { instance_double('Uploadcare::UserAgent') }
11
8
 
12
- context "if user_agent is not specified in method's options" do
13
- it 'builds user-agent from ruby version, gem version and public key' do
14
- expected = /#{Gem.ruby_version}\/#{described_class::VERSION}\/test/
15
- expect( Uploadcare.user_agent(public_key: 'test') ).to match(expected)
16
- end
9
+ it 'returns user agent string' do
10
+ allow(Uploadcare::UserAgent).to receive(:new) { user_agent_builder }
11
+ expect(user_agent_builder).to receive(:call).with(options) { 'user/agent' }
12
+
13
+ expect(user_agent).to eq('user/agent')
17
14
  end
18
15
  end
19
-
20
16
  end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Uploadcare::UserAgent do
4
+ subject(:user_agent) { described_class.new.call(options) }
5
+
6
+ before do
7
+ stub_const('Uploadcare::VERSION', '123')
8
+ allow(Gem).to receive(:ruby_version) { '456' }
9
+ end
10
+
11
+ context 'when user_agent option is set' do
12
+ let(:options) do
13
+ { user_agent: 'predefined user agent' }
14
+ end
15
+
16
+ it { is_expected.to eq('predefined user agent') }
17
+ end
18
+
19
+ context 'when user_agent_environment option is set' do
20
+ let(:options) do
21
+ {
22
+ public_key: 'pubkey',
23
+ user_agent_environment: {
24
+ framework_name: 'rails',
25
+ framework_version: '5.1.0',
26
+ extension_name: 'UploadcareRails',
27
+ extension_version: '1.1.0'
28
+ }
29
+ }
30
+ end
31
+
32
+ it do
33
+ is_expected.to eq(
34
+ 'UploadcareRuby/123/pubkey (Ruby/456; rails/5.1.0; UploadcareRails/1.1.0)'
35
+ )
36
+ end
37
+ end
38
+
39
+ context 'when user_agent_environment option is not set' do
40
+ let(:options) do
41
+ { public_key: 'pubkey' }
42
+ end
43
+
44
+ it { is_expected.to eq('UploadcareRuby/123/pubkey (Ruby/456)') }
45
+ end
46
+ end
metadata CHANGED
@@ -1,113 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
- - '@rastyagaev (Vadim Rastyagaev)'
8
- - '@dimituri (Dimitry Solovyov)'
9
- - '@romanonthego (Roman Dubinin)'
7
+ - "@rastyagaev (Vadim Rastyagaev)"
8
+ - "@dimituri (Dimitry Solovyov)"
9
+ - "@romanonthego (Roman Dubinin)"
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-03-21 00:00:00.000000000 Z
13
+ date: 2018-05-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0.8'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0.8'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: faraday_middleware
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0.9'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0.9'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: multipart-post
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: mime-types
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - '>='
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - ~>
75
+ - - "~>"
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - ~>
82
+ - - "~>"
83
83
  - !ruby/object:Gem::Version
84
84
  version: '3'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rake
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: pry
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - '>='
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - '>='
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  description: " Ruby wrapper for Uploadcare service API. \n
@@ -119,9 +119,9 @@ executables: []
119
119
  extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
- - .DS_Store
123
- - .gitignore
124
- - .travis.yml
122
+ - ".DS_Store"
123
+ - ".gitignore"
124
+ - ".travis.yml"
125
125
  - CHANGELOG.md
126
126
  - Gemfile
127
127
  - LICENSE
@@ -151,6 +151,7 @@ files:
151
151
  - lib/uploadcare/rest/middlewares/parse_json_middleware.rb
152
152
  - lib/uploadcare/rest/middlewares/raise_error_middleware.rb
153
153
  - lib/uploadcare/utils/parser.rb
154
+ - lib/uploadcare/utils/user_agent.rb
154
155
  - lib/uploadcare/version.rb
155
156
  - spec/api/raw_api_spec.rb
156
157
  - spec/resources/file_list_spec.rb
@@ -169,6 +170,7 @@ files:
169
170
  - spec/uploading/uploading_multiple_spec.rb
170
171
  - spec/uploading/uploading_spec.rb
171
172
  - spec/utils/parser_spec.rb
173
+ - spec/utils/user_agent_spec.rb
172
174
  - spec/view.png
173
175
  - spec/view2.jpg
174
176
  - uploadcare-ruby.gemspec
@@ -184,17 +186,17 @@ require_paths:
184
186
  - lib
185
187
  required_ruby_version: !ruby/object:Gem::Requirement
186
188
  requirements:
187
- - - '>='
189
+ - - ">="
188
190
  - !ruby/object:Gem::Version
189
191
  version: '0'
190
192
  required_rubygems_version: !ruby/object:Gem::Requirement
191
193
  requirements:
192
- - - '>='
194
+ - - ">="
193
195
  - !ruby/object:Gem::Version
194
196
  version: '0'
195
197
  requirements: []
196
198
  rubyforge_project:
197
- rubygems_version: 2.0.14.1
199
+ rubygems_version: 2.5.2
198
200
  signing_key:
199
201
  specification_version: 4
200
202
  summary: Ruby gem for Uploadcare
@@ -216,5 +218,6 @@ test_files:
216
218
  - spec/uploading/uploading_multiple_spec.rb
217
219
  - spec/uploading/uploading_spec.rb
218
220
  - spec/utils/parser_spec.rb
221
+ - spec/utils/user_agent_spec.rb
219
222
  - spec/view.png
220
223
  - spec/view2.jpg