benzboy 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b57f83c5b8c347df7237f3f7dfe66c446107f1ee
4
+ data.tar.gz: 9569a8c03e7f3e50ce4b02b0e3f5e5f6d80957d8
5
+ SHA512:
6
+ metadata.gz: 7abf0b8d9713d0a7f0202dc53f3bdbbdbf75d5fc818a2affa169f08f264495e8b760dedd493761a46c6610149b1f52412e02c2e2d9899e183dcaf9c680cedd8c
7
+ data.tar.gz: 5835a9f3ddc653224005465f852a5ae1f69fe4f4d7579c467a8f18de756ef656b8a23c402539c8f7c624d55808416f6cf88c41f730f9079212dee8e60640c5c7
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in benzboy.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sarath Mantrala
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.
@@ -0,0 +1,31 @@
1
+ # Benzboy
2
+
3
+ A tutorial to show how to wrap an external api in to a gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'benzboy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install benzboy
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/benzboy/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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'benzboy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "benzboy"
8
+ spec.version = Benzboy::VERSION
9
+ spec.authors = ["Sarath Mantrala"]
10
+ spec.email = ["sarath.mantrala@gmail.com"]
11
+ spec.summary = %q{ Ruby gem to wrap any API }
12
+ spec.description = %q{ A very basic ruby gem to show how to wrap any API }
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock"
26
+
27
+ spec.add_dependency "faraday"
28
+ spec.add_dependency "json"
29
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "benzboy/version"
2
+ require_relative "benzboy/car"
3
+
4
+ module Benzboy
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,36 @@
1
+ require'faraday'
2
+ require 'json'
3
+
4
+ API_URL = "http://www.benzboy.com/api/v1/cars/active"
5
+ # API_URL = "http://www.bensbenzes.com/api/v1/cars/active"
6
+
7
+ module Benzboy
8
+ class Car
9
+ attr_reader :id, :make, :model, :year, :color, :vin, :dealer_id
10
+
11
+ def initialize(attributes)
12
+ @id = attributes["id"]
13
+ @make = attributes["make"]
14
+ @model = attributes["model"]
15
+ @year = attributes["year"]
16
+ @color = attributes["color"]
17
+ @vin = attributes["vin"]
18
+ @dealer_id = attributes["dealer_id"]
19
+ end
20
+
21
+ def self.find(id)
22
+ response = Faraday.get("#{API_URL}/#{id}")
23
+ response = "{
24
+ \"id\": 68,
25
+ \"make\": \"Honda\",
26
+ \"model\": \"Civic\",
27
+ \"year\": \"1996\",
28
+ \"color\": \"Blue\",
29
+ \"vin\": \"XXXXXXXXXXXXXX\",
30
+ \"dealer_id\": 34
31
+ }"
32
+ attributes = JSON.parse(response)
33
+ new(attributes)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Benzboy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ require './test/test_helper'
2
+
3
+ class BenzCarTest < Minitest::Test
4
+ def test_exists
5
+ assert Benzboy::Car
6
+ end
7
+
8
+ def test_it_gives_a_single_car
9
+ VCR.use_cassette('one_car') do
10
+ car = Benzboy::Car.find(68)
11
+ assert_equal Benzboy::Car, car.class
12
+
13
+ # Check that the fields are accessible by our model
14
+ assert_equal 68, car.id
15
+ assert_equal "Honda", car.make
16
+ assert_equal "Civic", car.model
17
+ assert_equal "1996", car.year
18
+ assert_equal "Blue", car.color
19
+ assert_equal "XXXXXXXXXXXXXX", car.vin
20
+ assert_equal 34, car.dealer_id
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.benzboy.com/api/v1/cars/active/68
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ Date:
22
+ - Fri, 26 Sep 2014 04:47:39 GMT
23
+ Server:
24
+ - Apache
25
+ Accept-Ranges:
26
+ - bytes
27
+ Vary:
28
+ - Accept-Encoding
29
+ Content-Length:
30
+ - '1108'
31
+ Content-Type:
32
+ - text/html
33
+ body:
34
+ encoding: UTF-8
35
+ string: "<!-- SHTML Wrapper - 404 Not Found -->\n<!DOCTYPE html>\n<html>\n <head>\n
36
+ \ <title>404 Not Found</title>\n <meta name=\"revisit-after\" content=\"10\">\n
37
+ \ <meta name=\"ROBOTS\" content=\"NOINDEX, NOFOLLOW\"> \n <script type=\"text/javascript\"
38
+ src=\"http://cdn.dsultra.com/js/registrar.js\"></script>\n <link href=\"http://cf.bluehost-cdn.com/media/shared/general/homelayout.css\"
39
+ rel=\"stylesheet\" type=\"text/css\">\n <link rel=\"stylesheet\" href=\"http://cf.bluehost-cdn.com/media/shared/general/_bh/homestyle.css\"
40
+ type=\"text/css\">\n \n <style>\n body{\n margin:25px;\n
41
+ \ }\n .t1{\n color:#000000;\n font-family: Arial, Helvetica,
42
+ sans-serif;\n font-size:14px;\n }\n .t2{\n color:#3d3d3d;\n
43
+ \ font-family: Arial, Helvetica, sans-serif;\n font-size:10px;\n
44
+ \ white-space:nowrap;\n }\n .icontent {\n width: 1025px;\n
45
+ \ height: 700px;\n border: none;\n margin-top: 4px;\n
46
+ \ margin-bottom: 4px;\n }\n h1 {\n font-size: 18px;\n
47
+ \ display: block;\n }\n h2 {\n font-size: 16px;\n }\n
48
+ \ ul {\n margin-left: 34%\n }\n </style>\n</head>\n<body
49
+ bgcolor=white>\n\n<div style=\"border: solid 2px;border-color: #033B73;padding:
50
+ 0px;width: 1065px;margin: 0 auto;\">\n <table cellpadding=\"0\" cellspacing=\"0\"
51
+ border=\"0\" width=\"1065\">\n <tr>\n <td colspan=\"2\" class=\"topheading\">\n
52
+ \ <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>\n <td
53
+ style=\"padding-left:25px;width:205px;height:90px\"><a href=\"http://www.bluehost.com/\"><img
54
+ src=\"http://cf.bluehost-cdn.com/media/shared/general/_bh/logo.gif\" width=\"178\"
55
+ height=\"39\" alt=\"bluehost\" border=\"0\"></a></td>\n <td style=\"text-align:left\">Affordable,
56
+ Reliable<br />Web Hosting Solutions.</td>\n </tr></table>\n </td>\n
57
+ \ </tr>\n </table>\n <div style=\"text-align: center\">\n <h1>404
58
+ Error File Not Found</h1>\n <h2> The page you are looking for might have
59
+ been removed, <br />had its name changed, or is temporarily unavailable.</h2>\n
60
+ \ <iframe frameborder=\"0\" scrolling=\"no\" src=\"about:blank\"
61
+ id='ad_frame' class=\"icontent\"></iframe>\n <script type=\"text/javascript\">registrar_frameset({a_id:
62
+ 143209, drid: \"as-drid-2578124767373827\", frame: \"ad_frame\"});</script>\n
63
+ \ <p><a href=\"http://www.bluehost.com\">Web Hosting</a> provided
64
+ by Bluehost.com</p>\n </div>\n </div>\n</body>\n</html>\n\n"
65
+ http_version:
66
+ recorded_at: Fri, 26 Sep 2014 04:49:49 GMT
67
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,9 @@
1
+ require './lib/benzboy'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'test/fixtures'
8
+ c.hook_into :webmock
9
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: benzboy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sarath Mantrala
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: minitest
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: vcr
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: webmock
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: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: " A very basic ruby gem to show how to wrap any API "
112
+ email:
113
+ - sarath.mantrala@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - benzboy.gemspec
124
+ - lib/benzboy.rb
125
+ - lib/benzboy/car.rb
126
+ - lib/benzboy/version.rb
127
+ - test/car/car_test.rb
128
+ - test/fixtures/one_car.yml
129
+ - test/test_helper.rb
130
+ homepage: ''
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.1
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Ruby gem to wrap any API
154
+ test_files:
155
+ - test/car/car_test.rb
156
+ - test/fixtures/one_car.yml
157
+ - test/test_helper.rb