json_client 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f417e4ea4aa055a0b430860a252a43c30d11db30
4
+ data.tar.gz: b37605aa0bbe431f75313288e2061cdd6da3651e
5
+ SHA512:
6
+ metadata.gz: 00e47ebbf6d376b26cbe63dcabb94a52c77ba8a0b412970448c6dfe3643d158e3f2eb9cc1dc62f373e04699e1c6eeb21df8a10f515b822abb7715046fc26ceba
7
+ data.tar.gz: 3e027176248cbe4247bf63903e69c3ed4321ad8c65fb5997dcc68f2da5fe7bd509ecd0e9830742278b305285601c9e3b834c98d68749e889a8748e4d3c9f075a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.0
5
+
6
+ gemfile:
7
+ - Gemfile
8
+
9
+ cache: bundler
10
+
11
+ before_script: "bundle update"
12
+
13
+ script: "bundle exec rake spec"
14
+
15
+ notifications:
16
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in json_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 johnmcconnell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # JsonClient
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'json_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install json_client
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/json_client/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task default: :spec
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'json_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "json_client"
8
+ spec.version = JsonClient::VERSION
9
+ spec.authors = ["johnmcconnell"]
10
+ spec.email = ["johnnyillinois@gmail.com"]
11
+ spec.summary = %q{crud json client to make creating services easy'}
12
+ spec.description = %q{crud json client to make creating services easy'}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rest-client', '~> 1.7.2'
22
+
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec-collection_matchers"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "webmock"
28
+ end
@@ -0,0 +1,111 @@
1
+ require 'rest_client'
2
+
3
+ require_relative 'abstract_responses/index'
4
+ require_relative 'abstract_responses/show'
5
+ require_relative 'abstract_responses/create'
6
+ require_relative 'abstract_responses/update'
7
+ require_relative 'abstract_responses/destroy'
8
+
9
+ module JsonClient
10
+ class AbstractClient
11
+ attr_reader :api_key, :api_password, :pather
12
+
13
+ def initialize(pather, config)
14
+ @api_key = config[:api_key]
15
+ @api_password = config[:api_password]
16
+ @pather = pather
17
+ validate_variables
18
+ end
19
+
20
+ def index
21
+ uri = request_path
22
+ response = RestClient.get uri, params: auth_params
23
+ index_response_factory.new(response.body, response.code)
24
+ end
25
+
26
+ def show(id)
27
+ uri = request_path(id)
28
+ response = RestClient.get uri, params: auth_params
29
+ show_response_factory.new(response.body, response.code)
30
+ end
31
+
32
+ def create(model)
33
+ uri = request_path
34
+ response = RestClient.post(
35
+ uri,
36
+ auth_params.merge(create_params(model)).to_json,
37
+ content_type: :json,
38
+ accept: :json
39
+ )
40
+ create_response_factory.new(response.body, response.code)
41
+ end
42
+
43
+ def update(id, model)
44
+ uri = request_path(id)
45
+ response = RestClient.put(
46
+ uri,
47
+ auth_params.merge(update_params(model)).to_json,
48
+ content_type: :json,
49
+ accept: :json
50
+ )
51
+ update_response_factory.new(response.body, response.code)
52
+ end
53
+
54
+ def destroy(id)
55
+ uri = request_path(id)
56
+ response = RestClient.delete(
57
+ uri, params: auth_params
58
+ )
59
+ destroy_response_factory.new(response.body, response.code)
60
+ end
61
+
62
+ protected
63
+
64
+ def index_response_factory
65
+ AbstractResponses::Index
66
+ end
67
+
68
+ def show_response_factory
69
+ AbstractResponses::Show
70
+ end
71
+
72
+ def create_response_factory
73
+ AbstractResponses::Create
74
+ end
75
+
76
+ def update_response_factory
77
+ AbstractResponses::Update
78
+ end
79
+
80
+ def destroy_response_factory
81
+ AbstractResponses::Destroy
82
+ end
83
+
84
+ def create_params(model)
85
+ model.to_json
86
+ end
87
+
88
+ def update_params(model)
89
+ model.to_json
90
+ end
91
+
92
+ def request_path(id = nil)
93
+ pather.path(id)
94
+ end
95
+
96
+ def auth_params
97
+ {
98
+ api_key: api_key,
99
+ api_password: api_password
100
+ }
101
+ end
102
+
103
+ private
104
+
105
+ def validate_variables
106
+ fail 'api_key must be set' if api_key.nil?
107
+ fail 'api_password must be set' if api_key.nil?
108
+ fail 'pather must be set' if api_key.nil?
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'response'
2
+
3
+ module JsonClient
4
+ module AbstractResponses
5
+ class Create < Response
6
+ def initialize(body, code)
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'response'
2
+
3
+ module JsonClient
4
+ module AbstractResponses
5
+ class Destroy < Response
6
+ def initialize(body, code)
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'response'
2
+
3
+ module JsonClient
4
+ module AbstractResponses
5
+ class Index < Response
6
+ def initialize(body, code)
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module JsonClient
2
+ module AbstractResponses
3
+ class Response
4
+ attr_reader :body, :code
5
+
6
+ def initialize(body, code)
7
+ @body = body
8
+ @code = code
9
+ end
10
+
11
+ def json
12
+ parse_json
13
+ end
14
+
15
+ def success?
16
+ code >= 200 && code < 300
17
+ end
18
+
19
+ protected
20
+
21
+ def parse_json
22
+ @parse_json ||= JSON.parse(body)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'response'
2
+
3
+ module JsonClient
4
+ module AbstractResponses
5
+ class Show < Response
6
+ def initialize(body, code)
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'response'
2
+
3
+ module JsonClient
4
+ module AbstractResponses
5
+ class Update < Response
6
+ def initialize(body, code)
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module JsonClient
3
+ class Pather
4
+ attr_reader :host, :ext, :name
5
+
6
+ def initialize(host, ext, name)
7
+ @host = host
8
+ @ext = ext
9
+ @name = name
10
+ end
11
+
12
+ def path(id = nil)
13
+ if id.nil?
14
+ "#{host}/#{ext}/#{name}"
15
+ else
16
+ "#{host}/#{ext}/#{name}/#{id}"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module JsonClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "json_client/version"
2
+ require "json_client/abstract_client"
3
+ require "json_client/pather"
4
+
5
+ module JsonClient
6
+ def self.new(pather, config)
7
+ AbstractClient.new(pather, config)
8
+ end
9
+ end
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Cowboy
23
+ Date:
24
+ - Sun, 04 Jan 2015 20:36:27 GMT
25
+ Connection:
26
+ - keep-alive
27
+ X-Frame-Options:
28
+ - SAMEORIGIN
29
+ X-Xss-Protection:
30
+ - 1; mode=block
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Etag:
36
+ - '"d750f6d7ca4471b89f25e4d5c7fa8d78"'
37
+ Cache-Control:
38
+ - max-age=0, private, must-revalidate
39
+ X-Request-Id:
40
+ - 0c59d284-8ebb-4bbc-9077-a4485d9a5762
41
+ X-Runtime:
42
+ - '0.102701'
43
+ Transfer-Encoding:
44
+ - chunked
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"accounts":[]}'
50
+ http_version:
51
+ recorded_at: Sun, 04 Jan 2015 20:36:28 GMT
52
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/authentications/authenticate
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"api_key":"124ecd49-07fd-4553-a5cd-0178b7fa8b3f","api_password":"IIoclO7kmQqJ1wixWrAuOA","account":{"username":"new_username","password":"new_password"}}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '154'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - Cowboy
27
+ Date:
28
+ - Mon, 05 Jan 2015 01:23:42 GMT
29
+ Connection:
30
+ - keep-alive
31
+ X-Frame-Options:
32
+ - SAMEORIGIN
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Etag:
40
+ - '"29a332b9c56931be8b665c71c76164f8"'
41
+ Cache-Control:
42
+ - max-age=0, private, must-revalidate
43
+ Set-Cookie:
44
+ - request_method=POST; path=/
45
+ X-Request-Id:
46
+ - aa1a198c-8128-4be7-a69a-6bfafd673aac
47
+ X-Runtime:
48
+ - '0.387137'
49
+ Transfer-Encoding:
50
+ - chunked
51
+ Via:
52
+ - 1.1 vegur
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"authenticated":true}'
56
+ http_version:
57
+ recorded_at: Mon, 05 Jan 2015 01:09:52 GMT
58
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"api_key":"124ecd49-07fd-4553-a5cd-0178b7fa8b3f","api_password":"IIoclO7kmQqJ1wixWrAuOA","account":{"username":"new_username","password":"new_password"}}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '154'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - Cowboy
27
+ Date:
28
+ - Sun, 04 Jan 2015 20:36:27 GMT
29
+ Connection:
30
+ - keep-alive
31
+ X-Frame-Options:
32
+ - SAMEORIGIN
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Etag:
40
+ - '"f26adbb79ceaf5aaa609ed1819b600b6"'
41
+ Cache-Control:
42
+ - max-age=0, private, must-revalidate
43
+ Set-Cookie:
44
+ - request_method=POST; path=/
45
+ X-Request-Id:
46
+ - b554584e-ac2f-45ee-859e-d89f414c7aed
47
+ X-Runtime:
48
+ - '0.201978'
49
+ Transfer-Encoding:
50
+ - chunked
51
+ Via:
52
+ - 1.1 vegur
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"id":6,"username":"new_username","created_at":"2015-01-04T20:36:28.339Z","updated_at":"2015-01-04T20:36:28.339Z"}'
56
+ http_version:
57
+ recorded_at: Sun, 04 Jan 2015 20:36:28 GMT
58
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,109 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"api_key":"124ecd49-07fd-4553-a5cd-0178b7fa8b3f","api_password":"IIoclO7kmQqJ1wixWrAuOA","account":{"username":"new_username_2","password":"new_password_2"}}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '158'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - Cowboy
27
+ Date:
28
+ - Sun, 04 Jan 2015 20:48:55 GMT
29
+ Connection:
30
+ - keep-alive
31
+ X-Frame-Options:
32
+ - SAMEORIGIN
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Etag:
40
+ - '"03258793b9ebad43ea73e9565d861f80"'
41
+ Cache-Control:
42
+ - max-age=0, private, must-revalidate
43
+ Set-Cookie:
44
+ - request_method=POST; path=/
45
+ X-Request-Id:
46
+ - a764b58c-eda2-4770-9ef3-87fb2bf7854c
47
+ X-Runtime:
48
+ - '0.201380'
49
+ Transfer-Encoding:
50
+ - chunked
51
+ Via:
52
+ - 1.1 vegur
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"id":10,"username":"new_username_2","created_at":"2015-01-04T20:48:55.695Z","updated_at":"2015-01-04T20:48:55.695Z"}'
56
+ http_version:
57
+ recorded_at: Sun, 04 Jan 2015 20:48:55 GMT
58
+ - request:
59
+ method: delete
60
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts/10?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
61
+ body:
62
+ encoding: US-ASCII
63
+ string: ''
64
+ headers:
65
+ Accept:
66
+ - "*/*; q=0.5, application/xml"
67
+ Accept-Encoding:
68
+ - gzip, deflate
69
+ User-Agent:
70
+ - Ruby
71
+ response:
72
+ status:
73
+ code: 200
74
+ message: OK
75
+ headers:
76
+ Server:
77
+ - Cowboy
78
+ Date:
79
+ - Sun, 04 Jan 2015 20:48:55 GMT
80
+ Connection:
81
+ - keep-alive
82
+ X-Frame-Options:
83
+ - SAMEORIGIN
84
+ X-Xss-Protection:
85
+ - 1; mode=block
86
+ X-Content-Type-Options:
87
+ - nosniff
88
+ Content-Type:
89
+ - application/json; charset=utf-8
90
+ Etag:
91
+ - '"db2883d5f032d326e56b7f4d896e51e9"'
92
+ Cache-Control:
93
+ - max-age=0, private, must-revalidate
94
+ Set-Cookie:
95
+ - request_method=DELETE; path=/
96
+ X-Request-Id:
97
+ - a4863ea3-30e9-48b1-91c9-628a1b10a858
98
+ X-Runtime:
99
+ - '0.119341'
100
+ Transfer-Encoding:
101
+ - chunked
102
+ Via:
103
+ - 1.1 vegur
104
+ body:
105
+ encoding: UTF-8
106
+ string: '{"id":10}'
107
+ http_version:
108
+ recorded_at: Sun, 04 Jan 2015 20:48:55 GMT
109
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts/6?api_key=124ecd49-07fd-4553-a5cd-0178b7fa8b3f&api_password=IIoclO7kmQqJ1wixWrAuOA
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Cowboy
23
+ Date:
24
+ - Sun, 04 Jan 2015 20:37:35 GMT
25
+ Connection:
26
+ - keep-alive
27
+ X-Frame-Options:
28
+ - SAMEORIGIN
29
+ X-Xss-Protection:
30
+ - 1; mode=block
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Etag:
36
+ - '"f26adbb79ceaf5aaa609ed1819b600b6"'
37
+ Cache-Control:
38
+ - max-age=0, private, must-revalidate
39
+ X-Request-Id:
40
+ - 31c54ba5-3226-4433-9950-ddd9fadc1c64
41
+ X-Runtime:
42
+ - '0.105063'
43
+ Transfer-Encoding:
44
+ - chunked
45
+ Via:
46
+ - 1.1 vegur
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"id":6,"username":"new_username","created_at":"2015-01-04T20:36:28.339Z","updated_at":"2015-01-04T20:36:28.339Z"}'
50
+ http_version:
51
+ recorded_at: Sun, 04 Jan 2015 20:37:35 GMT
52
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,113 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"api_key":"124ecd49-07fd-4553-a5cd-0178b7fa8b3f","api_password":"IIoclO7kmQqJ1wixWrAuOA","account":{"username":"new_username_1","password":"new_password_1"}}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '158'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - Cowboy
27
+ Date:
28
+ - Sun, 04 Jan 2015 20:36:28 GMT
29
+ Connection:
30
+ - keep-alive
31
+ X-Frame-Options:
32
+ - SAMEORIGIN
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ Content-Type:
38
+ - application/json; charset=utf-8
39
+ Etag:
40
+ - '"f21a93c307ee794341d6e751a83b5c44"'
41
+ Cache-Control:
42
+ - max-age=0, private, must-revalidate
43
+ Set-Cookie:
44
+ - request_method=POST; path=/
45
+ X-Request-Id:
46
+ - 60e75ec5-53eb-4552-8e86-29f2271351ee
47
+ X-Runtime:
48
+ - '0.199750'
49
+ Transfer-Encoding:
50
+ - chunked
51
+ Via:
52
+ - 1.1 vegur
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"id":7,"username":"new_username_1","created_at":"2015-01-04T20:36:28.949Z","updated_at":"2015-01-04T20:36:28.949Z"}'
56
+ http_version:
57
+ recorded_at: Sun, 04 Jan 2015 20:36:28 GMT
58
+ - request:
59
+ method: put
60
+ uri: http://account-authenticator.herokuapp.com/api/v1/accounts/7
61
+ body:
62
+ encoding: UTF-8
63
+ string: '{"api_key":"124ecd49-07fd-4553-a5cd-0178b7fa8b3f","api_password":"IIoclO7kmQqJ1wixWrAuOA","account":{"username":"updated_username","password":"updated_password"}}'
64
+ headers:
65
+ Accept:
66
+ - application/json
67
+ Accept-Encoding:
68
+ - gzip, deflate
69
+ Content-Type:
70
+ - application/json
71
+ Content-Length:
72
+ - '162'
73
+ User-Agent:
74
+ - Ruby
75
+ response:
76
+ status:
77
+ code: 200
78
+ message: OK
79
+ headers:
80
+ Server:
81
+ - Cowboy
82
+ Date:
83
+ - Sun, 04 Jan 2015 20:36:28 GMT
84
+ Connection:
85
+ - keep-alive
86
+ X-Frame-Options:
87
+ - SAMEORIGIN
88
+ X-Xss-Protection:
89
+ - 1; mode=block
90
+ X-Content-Type-Options:
91
+ - nosniff
92
+ Content-Type:
93
+ - application/json; charset=utf-8
94
+ Etag:
95
+ - '"80904310aa88a944d24696f6d4c81fa1"'
96
+ Cache-Control:
97
+ - max-age=0, private, must-revalidate
98
+ Set-Cookie:
99
+ - request_method=PUT; path=/
100
+ X-Request-Id:
101
+ - c82ee34e-2392-4999-a65b-e646f09a8495
102
+ X-Runtime:
103
+ - '0.253034'
104
+ Transfer-Encoding:
105
+ - chunked
106
+ Via:
107
+ - 1.1 vegur
108
+ body:
109
+ encoding: UTF-8
110
+ string: '{"id":7,"username":"updated_username","created_at":"2015-01-04T20:36:28.949Z","updated_at":"2015-01-04T20:36:29.353Z"}'
111
+ http_version:
112
+ recorded_at: Sun, 04 Jan 2015 20:36:29 GMT
113
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'rspec/collection_matchers'
3
+ require 'json_client'
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
8
+ c.hook_into :webmock
9
+ end
10
+
11
+ describe JsonClient do
12
+ let(:config) do
13
+ {
14
+ api_key: '124ecd49-07fd-4553-a5cd-0178b7fa8b3f',
15
+ api_password: 'IIoclO7kmQqJ1wixWrAuOA',
16
+ host: 'http://account-authenticator.herokuapp.com'
17
+ }
18
+ end
19
+
20
+ describe '::register' do
21
+ it 'registers a configuration to be used when invoked with ::new' do
22
+ client = described_class.new(
23
+ JsonClient::Pather.new(
24
+ config[:host],
25
+ 'etc',
26
+ 'end'
27
+ ),
28
+ config
29
+ )
30
+ expect(client.pather.host).to eq config[:host]
31
+ expect(client.api_key).to eq config[:api_key]
32
+ expect(client.api_password).to eq config[:api_password]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ require 'json_client'
2
+ require 'vcr'
3
+
4
+ class SpecHelper
5
+ end
6
+
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - johnmcconnell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-collection_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: crud json client to make creating services easy'
98
+ email:
99
+ - johnnyillinois@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - json_client.gemspec
111
+ - lib/json_client.rb
112
+ - lib/json_client/abstract_client.rb
113
+ - lib/json_client/abstract_responses/create.rb
114
+ - lib/json_client/abstract_responses/destroy.rb
115
+ - lib/json_client/abstract_responses/index.rb
116
+ - lib/json_client/abstract_responses/response.rb
117
+ - lib/json_client/abstract_responses/show.rb
118
+ - lib/json_client/abstract_responses/update.rb
119
+ - lib/json_client/pather.rb
120
+ - lib/json_client/version.rb
121
+ - spec/fixtures/vcr_cassettes/all_success.yml
122
+ - spec/fixtures/vcr_cassettes/authenticate_success.yml
123
+ - spec/fixtures/vcr_cassettes/create_success.yml
124
+ - spec/fixtures/vcr_cassettes/destroy_success.yml
125
+ - spec/fixtures/vcr_cassettes/show_success.yml
126
+ - spec/fixtures/vcr_cassettes/update_success.yml
127
+ - spec/json_client_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: ''
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: crud json client to make creating services easy'
153
+ test_files:
154
+ - spec/fixtures/vcr_cassettes/all_success.yml
155
+ - spec/fixtures/vcr_cassettes/authenticate_success.yml
156
+ - spec/fixtures/vcr_cassettes/create_success.yml
157
+ - spec/fixtures/vcr_cassettes/destroy_success.yml
158
+ - spec/fixtures/vcr_cassettes/show_success.yml
159
+ - spec/fixtures/vcr_cassettes/update_success.yml
160
+ - spec/json_client_spec.rb
161
+ - spec/spec_helper.rb