percy-client 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.
- checksums.yaml +4 -4
- data/lib/percy.rb +6 -7
- data/lib/percy/client.rb +3 -17
- data/lib/percy/client/builds.rb +2 -2
- data/lib/percy/client/connection.rb +4 -1
- data/lib/percy/client/resources.rb +1 -1
- data/lib/percy/client/snapshots.rb +1 -1
- data/lib/percy/client/version.rb +1 -1
- data/lib/percy/config.rb +28 -0
- data/spec/lib/percy/client/connection_spec.rb +6 -6
- data/spec/lib/percy/client_spec.rb +5 -13
- data/spec/lib/percy_spec.rb +21 -0
- data/spec/spec_helper.rb +2 -5
- metadata +5 -4
- data/spec/support/test_helpers.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac390ac562cecfd4bf1d32a46d95e9ec544f7eb3
|
4
|
+
data.tar.gz: 14920f3b71e0038f51dd6bb10c30af279e5631e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4c7491bfa30fff592390a09c0d83dc23e621ab523fe71ef82b7b173dd7d4118b59e9aea942b8eb59aaedf45298f84516e13fb2355ce8d197a9d01856696426f
|
7
|
+
data.tar.gz: 23ab3e161e502438af1ae6bc4f4661c7fca4e46b6b060d0bf1c2b57d5481d5d0fb415237d8e59f7be05c9db52831d1d93ac9107af1f533ba38f22921088454f7
|
data/lib/percy.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
require 'percy/client'
|
2
2
|
|
3
3
|
module Percy
|
4
|
-
|
5
|
-
|
4
|
+
def self.config
|
5
|
+
@config ||= Percy::Config.new
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.
|
9
|
-
|
10
|
-
|
11
|
-
}
|
8
|
+
def self.reset
|
9
|
+
@config = nil
|
10
|
+
@client = nil
|
12
11
|
end
|
13
12
|
|
14
13
|
# API client based on configured options.
|
15
14
|
#
|
16
15
|
# @return [Percy::Client] API client.
|
17
16
|
def self.client
|
18
|
-
@client = Percy::Client.new(
|
17
|
+
@client = Percy::Client.new(config: config) if !defined?(@client) || !@client
|
19
18
|
@client
|
20
19
|
end
|
21
20
|
|
data/lib/percy/client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'percy/config'
|
2
3
|
require 'percy/client/connection'
|
3
4
|
require 'percy/client/local_git'
|
4
5
|
require 'percy/client/version'
|
@@ -23,25 +24,10 @@ module Percy
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
API_VERSION = ENV['PERCY_API_VERSION'] || 'v1'
|
28
|
-
|
29
|
-
attr_accessor :access_token
|
27
|
+
attr_reader :config
|
30
28
|
|
31
29
|
def initialize(options = {})
|
32
|
-
@
|
33
|
-
end
|
34
|
-
|
35
|
-
def base_url
|
36
|
-
API_BASE_URL
|
37
|
-
end
|
38
|
-
|
39
|
-
def base_path
|
40
|
-
"/api/#{API_VERSION}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def full_base
|
44
|
-
"#{base_url}#{base_path}"
|
30
|
+
@config = options[:config] || Percy::Config.new
|
45
31
|
end
|
46
32
|
end
|
47
33
|
end
|
data/lib/percy/client/builds.rb
CHANGED
@@ -19,11 +19,11 @@ module Percy
|
|
19
19
|
},
|
20
20
|
}
|
21
21
|
}
|
22
|
-
post("#{
|
22
|
+
post("#{config.api_url}/repos/#{repo_slug}/builds/", data)
|
23
23
|
end
|
24
24
|
|
25
25
|
def finalize_build(build_id)
|
26
|
-
post("#{
|
26
|
+
post("#{config.api_url}/builds/#{build_id}/finalize", {})
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'uri'
|
1
2
|
require 'faraday'
|
2
3
|
|
3
4
|
module Percy
|
@@ -20,8 +21,10 @@ module Percy
|
|
20
21
|
|
21
22
|
def connection
|
22
23
|
return @connection if defined?(@connection)
|
24
|
+
parsed_uri = URI.parse(config.api_url)
|
25
|
+
base_url = "#{parsed_uri.scheme}://#{parsed_uri.host}:#{parsed_uri.port}"
|
23
26
|
@connection = Faraday.new(url: base_url) do |faraday|
|
24
|
-
faraday.request :token_auth,
|
27
|
+
faraday.request :token_auth, config.access_token if config.access_token
|
25
28
|
|
26
29
|
faraday.use Faraday::Adapter::HTTPClient
|
27
30
|
faraday.use Percy::Client::Connection::FaradayNiceErrorMiddleware
|
@@ -47,7 +47,7 @@ module Percy
|
|
47
47
|
},
|
48
48
|
}
|
49
49
|
begin
|
50
|
-
post("#{
|
50
|
+
post("#{config.api_url}/builds/#{build_id}/resources/", data)
|
51
51
|
rescue Percy::Client::ClientError => e
|
52
52
|
raise e if e.env.status != 409
|
53
53
|
STDERR.puts "[percy] Warning: unnecessary resource reuploaded with SHA-256: #{sha}"
|
data/lib/percy/client/version.rb
CHANGED
data/lib/percy/config.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Percy
|
2
|
+
class Config
|
3
|
+
# @!attribute [w] access_token
|
4
|
+
# @return [String] Percy repo access token.
|
5
|
+
# @!attribute api_url
|
6
|
+
# @return [String] Base URL for API requests. Default: https://percy.io/api/v1/
|
7
|
+
|
8
|
+
attr_accessor :access_token
|
9
|
+
attr_accessor :api_url
|
10
|
+
|
11
|
+
# List of configurable keys for {Percy::Client}
|
12
|
+
# @return [Array] Option keys.
|
13
|
+
def keys
|
14
|
+
@keys ||= [
|
15
|
+
:access_token,
|
16
|
+
:api_url,
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def access_token
|
21
|
+
@access_token ||= ENV['PERCY_TOKEN']
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_url
|
25
|
+
@api_url ||= ENV['PERCY_API'] || 'https://percy.io/api/v1'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
RSpec.describe Percy::Client::Connection do
|
2
2
|
describe '#get' do
|
3
|
-
it 'performs a GET request to the
|
4
|
-
stub_request(:get,
|
5
|
-
data = Percy.client.get(
|
3
|
+
it 'performs a GET request to the api_url and parses response' do
|
4
|
+
stub_request(:get, "#{Percy.config.api_url}/test").to_return(body: {foo: true}.to_json)
|
5
|
+
data = Percy.client.get("#{Percy.config.api_url}/test")
|
6
6
|
expect(data).to eq({'foo' => true})
|
7
7
|
end
|
8
8
|
end
|
9
9
|
describe '#post' do
|
10
|
-
it 'performs a POST request to the
|
11
|
-
stub_request(:post,
|
12
|
-
data = Percy.client.post(
|
10
|
+
it 'performs a POST request to the api_url and parses response' do
|
11
|
+
stub_request(:post, "#{Percy.config.api_url}/test").to_return(body: {foo: true}.to_json)
|
12
|
+
data = Percy.client.post("#{Percy.config.api_url}/test", {})
|
13
13
|
expect(data).to eq({'foo' => true})
|
14
14
|
end
|
15
15
|
end
|
@@ -1,17 +1,9 @@
|
|
1
1
|
RSpec.describe Percy::Client do
|
2
|
-
describe '#
|
3
|
-
it 'returns the
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
describe '#base_path' do
|
8
|
-
it 'returns the base API URL path' do
|
9
|
-
expect(Percy.client.base_path).to eq('/api/v1')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
describe '#full_base' do
|
13
|
-
it 'returns the full base API URL path' do
|
14
|
-
expect(Percy.client.full_base).to eq('http://localhost:3000/api/v1')
|
2
|
+
describe '#config' do
|
3
|
+
it 'returns the config object given when initialized' do
|
4
|
+
config = Percy::Config.new
|
5
|
+
client = Percy::Client.new(config: config)
|
6
|
+
expect(client.config).to eq(config)
|
15
7
|
end
|
16
8
|
end
|
17
9
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec.describe Percy do
|
2
|
+
before(:each) { Percy.reset }
|
3
|
+
describe '#config' do
|
4
|
+
it 'returns a config object' do
|
5
|
+
expect(Percy.config.api_url).to eq('http://localhost:3000/api/v1')
|
6
|
+
end
|
7
|
+
end
|
8
|
+
describe '#client' do
|
9
|
+
it 'returns a Percy::Client that is passed the global config object by default' do
|
10
|
+
config = Percy.config
|
11
|
+
expect(Percy.client.config).to eq(config)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe '#reset' do
|
15
|
+
it 'clears the main global config object' do
|
16
|
+
old_config = Percy.client.config
|
17
|
+
Percy.reset
|
18
|
+
expect(old_config).to_not eq(Percy.config)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
ENV['PERCY_API'] = 'http://localhost:3000'
|
1
|
+
ENV['PERCY_API'] = 'http://localhost:3000/api/v1'
|
2
2
|
|
3
|
-
require 'support/test_helpers'
|
4
3
|
require 'support/vcr_setup'
|
5
4
|
require 'webmock/rspec'
|
6
5
|
require 'percy'
|
7
6
|
|
8
7
|
RSpec.configure do |config|
|
9
|
-
config.include TestHelpers
|
10
|
-
|
11
8
|
config.expect_with :rspec do |expectations|
|
12
9
|
# This option will default to `true` in RSpec 4.
|
13
10
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
@@ -18,7 +15,7 @@ RSpec.configure do |config|
|
|
18
15
|
end
|
19
16
|
|
20
17
|
config.disable_monkey_patching!
|
21
|
-
config.warnings = true
|
18
|
+
# config.warnings = true
|
22
19
|
|
23
20
|
# Run specs in random order to surface order dependencies. If you find an
|
24
21
|
# order dependency and want to debug it, you can fix the order by providing
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/percy/client/resources.rb
|
132
132
|
- lib/percy/client/snapshots.rb
|
133
133
|
- lib/percy/client/version.rb
|
134
|
+
- lib/percy/config.rb
|
134
135
|
- percy-client.gemspec
|
135
136
|
- spec/cassettes/Percy_Client_Builds/_create_build/creates_a_build.yml
|
136
137
|
- spec/cassettes/Percy_Client_Builds/_finalize_build/finalizes_a_build.yml
|
@@ -143,8 +144,8 @@ files:
|
|
143
144
|
- spec/lib/percy/client/resources_spec.rb
|
144
145
|
- spec/lib/percy/client/snapshots_spec.rb
|
145
146
|
- spec/lib/percy/client_spec.rb
|
147
|
+
- spec/lib/percy_spec.rb
|
146
148
|
- spec/spec_helper.rb
|
147
|
-
- spec/support/test_helpers.rb
|
148
149
|
- spec/support/vcr_setup.rb
|
149
150
|
homepage: ''
|
150
151
|
licenses:
|
@@ -182,6 +183,6 @@ test_files:
|
|
182
183
|
- spec/lib/percy/client/resources_spec.rb
|
183
184
|
- spec/lib/percy/client/snapshots_spec.rb
|
184
185
|
- spec/lib/percy/client_spec.rb
|
186
|
+
- spec/lib/percy_spec.rb
|
185
187
|
- spec/spec_helper.rb
|
186
|
-
- spec/support/test_helpers.rb
|
187
188
|
- spec/support/vcr_setup.rb
|