remotr 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/remotr.rb +1 -0
- data/lib/remotr/respondable.rb +11 -9
- data/lib/remotr/test_helpers.rb +42 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 023a964c8e31c565831c7ca2d10b2c3528fdf144
|
4
|
+
data.tar.gz: 6effcc6e8e85fefd9c68a8c2599fb32fcef3a019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d16effe2c9b2a8c4a786f567f0b2b1486f04f926a53ee1dbb6d4ea347672d25f55ed8859014222c0b35e7d264f1aeb0efae11f8c627ec42f171812fff8e3ae1f
|
7
|
+
data.tar.gz: 13446fc8003d0c9ddbce0e2e92defafb7c5e118ea4f8380039b46a739e30327b90983bd22e6f9375f84a14a92eb260965a69c783407639c091fac0e471526e6d
|
data/lib/remotr.rb
CHANGED
data/lib/remotr/respondable.rb
CHANGED
@@ -25,7 +25,7 @@ module Remotr
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def post(path = {}, params = {}, body = nil)
|
28
|
-
request :post, path, params
|
28
|
+
request :post, path, params, body
|
29
29
|
end
|
30
30
|
|
31
31
|
def delete(path = {}, params = {})
|
@@ -33,17 +33,19 @@ module Remotr
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def put(path = {}, params = {}, body = nil)
|
36
|
-
request :put, path, params
|
36
|
+
request :put, path, params, body
|
37
37
|
end
|
38
38
|
|
39
|
-
def request(method, path, params, body = nil)
|
40
|
-
|
41
|
-
|
39
|
+
def request(method, path, params = {}, body = nil)
|
40
|
+
path = "#{config.base_path}#{path}"
|
41
|
+
token = Signature::Token.new application, config.api_key
|
42
|
+
request = Signature::Request.new method.to_s.upcase, path, params
|
43
|
+
auth_hash = request.sign token
|
44
|
+
query_params = params.merge auth_hash
|
45
|
+
url = URI.join(config.base_uri, path).to_s
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
headers: { 'Accept' => 'application/json' },
|
46
|
-
basic_auth: { username: 'api', password: config.api_key }
|
47
|
+
fail ArgumentError unless %w( get post delete put update ).include? method.to_s
|
48
|
+
HTTParty.send method, url, query: query_params, body: body, headers: { 'Accept' => 'application/json' }
|
47
49
|
end
|
48
50
|
|
49
51
|
def respond_with(httparty_response, custom_namespace = nil)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Remotr
|
2
|
+
module Test
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def redirect_httparty_to_rails_stack
|
6
|
+
redirect_httparty :get
|
7
|
+
redirect_httparty :post
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def redirect_httparty(method)
|
13
|
+
allow(HTTParty).to receive(method) do |url, options|
|
14
|
+
logger.warn "RSpec caught an outgoint HTTParty request to #{url.inspect} and re-routes it back into the Rails integration test framework..."
|
15
|
+
|
16
|
+
url = URI.parse url
|
17
|
+
# Why would you send requests to anywhere else but TLS encrypted and to something.example.com in the test environment?
|
18
|
+
expect(url.host).to include '.example.com'
|
19
|
+
expect(url.scheme).to eq 'https'
|
20
|
+
|
21
|
+
if options[:basic_auth].present?
|
22
|
+
options[:headers]['HTTP_AUTHORIZATION'] = "Basic " + Base64::encode64("#{options[:basic_auth][:username]}:#{options[:basic_auth][:password]}")
|
23
|
+
end
|
24
|
+
|
25
|
+
case method
|
26
|
+
when :post
|
27
|
+
query_string = options[:query].to_query.present? ? "?#{options[:query].to_query}" : nil
|
28
|
+
send method, "#{url.path}#{query_string}", options[:body], options[:headers]
|
29
|
+
when :get
|
30
|
+
send method, url.path, options[:query], options[:headers]
|
31
|
+
else
|
32
|
+
fail NotImplementedError
|
33
|
+
end
|
34
|
+
|
35
|
+
parsed_response = JSON.parse(response.body) rescue nil
|
36
|
+
OpenStruct.new code: response.code.to_i, parsed_response: parsed_response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remotr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bukowskis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/remotr/configurable.rb
|
120
120
|
- lib/remotr/configuration.rb
|
121
121
|
- lib/remotr/respondable.rb
|
122
|
+
- lib/remotr/test_helpers.rb
|
122
123
|
homepage: https://github.com/bukowskis/remotr
|
123
124
|
licenses: []
|
124
125
|
metadata: {}
|
@@ -141,6 +142,6 @@ rubyforge_project:
|
|
141
142
|
rubygems_version: 2.2.2
|
142
143
|
signing_key:
|
143
144
|
specification_version: 4
|
144
|
-
summary: Wrapping HTTParty
|
145
|
+
summary: Wrapping HTTParty
|
145
146
|
test_files: []
|
146
147
|
has_rdoc:
|