ga_example_gem 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ coverage
2
+ coverage.data
3
+ rdoc
4
+ doc
5
+ .yardoc
6
+ .bundle
7
+ pkg
8
+ .DS_Store
9
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ gem 'httparty'
10
+
11
+ group :development do
12
+ gem "shoulda", ">= 0"
13
+ gem "pry"
14
+ gem "rdoc", "~> 3.12"
15
+ gem "bundler", "~> 1.0"
16
+ gem "jeweler", "~> 1.8.7"
17
+ gem "simplecov"
18
+ end
19
+
20
+
21
+ group :test do
22
+ gem 'webmock'
23
+ gem 'simplecov'
24
+ gem 'coveralls'
25
+ gem 'rspec'
26
+ gem 'shoulda-matchers'
27
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,123 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.1)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.14)
12
+ builder (3.2.2)
13
+ coderay (1.1.0)
14
+ coveralls (0.7.0)
15
+ multi_json (~> 1.3)
16
+ rest-client
17
+ simplecov (>= 0.7)
18
+ term-ansicolor
19
+ thor
20
+ crack (0.4.1)
21
+ safe_yaml (~> 0.9.0)
22
+ diff-lcs (1.2.5)
23
+ docile (1.1.0)
24
+ faraday (0.8.8)
25
+ multipart-post (~> 1.2.0)
26
+ git (1.2.6)
27
+ github_api (0.10.1)
28
+ addressable
29
+ faraday (~> 0.8.1)
30
+ hashie (>= 1.2)
31
+ multi_json (~> 1.4)
32
+ nokogiri (~> 1.5.2)
33
+ oauth2
34
+ hashie (2.0.5)
35
+ highline (1.6.20)
36
+ httparty (0.12.0)
37
+ json (~> 1.8)
38
+ multi_xml (>= 0.5.2)
39
+ httpauth (0.2.0)
40
+ i18n (0.6.5)
41
+ jeweler (1.8.8)
42
+ builder
43
+ bundler (~> 1.0)
44
+ git (>= 1.2.5)
45
+ github_api (= 0.10.1)
46
+ highline (>= 1.6.15)
47
+ nokogiri (= 1.5.10)
48
+ rake
49
+ rdoc
50
+ json (1.8.1)
51
+ jwt (0.1.8)
52
+ multi_json (>= 1.5)
53
+ method_source (0.8.2)
54
+ mime-types (1.25.1)
55
+ minitest (4.7.5)
56
+ multi_json (1.8.2)
57
+ multi_xml (0.5.5)
58
+ multipart-post (1.2.0)
59
+ nokogiri (1.5.10)
60
+ oauth2 (0.9.2)
61
+ faraday (~> 0.8)
62
+ httpauth (~> 0.2)
63
+ jwt (~> 0.1.4)
64
+ multi_json (~> 1.0)
65
+ multi_xml (~> 0.5)
66
+ rack (~> 1.2)
67
+ pry (0.9.12.3)
68
+ coderay (~> 1.0)
69
+ method_source (~> 0.8)
70
+ slop (~> 3.4)
71
+ rack (1.5.2)
72
+ rake (10.1.0)
73
+ rdoc (3.12.2)
74
+ json (~> 1.4)
75
+ rest-client (1.6.7)
76
+ mime-types (>= 1.16)
77
+ rspec (2.14.1)
78
+ rspec-core (~> 2.14.0)
79
+ rspec-expectations (~> 2.14.0)
80
+ rspec-mocks (~> 2.14.0)
81
+ rspec-core (2.14.7)
82
+ rspec-expectations (2.14.4)
83
+ diff-lcs (>= 1.1.3, < 2.0)
84
+ rspec-mocks (2.14.4)
85
+ safe_yaml (0.9.7)
86
+ shoulda (3.5.0)
87
+ shoulda-context (~> 1.0, >= 1.0.1)
88
+ shoulda-matchers (>= 1.4.1, < 3.0)
89
+ shoulda-context (1.1.6)
90
+ shoulda-matchers (2.4.0)
91
+ activesupport (>= 3.0.0)
92
+ simplecov (0.8.2)
93
+ docile (~> 1.1.0)
94
+ multi_json
95
+ simplecov-html (~> 0.8.0)
96
+ simplecov-html (0.8.0)
97
+ slop (3.4.7)
98
+ term-ansicolor (1.2.2)
99
+ tins (~> 0.8)
100
+ thor (0.18.1)
101
+ thread_safe (0.1.3)
102
+ atomic
103
+ tins (0.12.0)
104
+ tzinfo (0.3.38)
105
+ webmock (1.15.0)
106
+ addressable (>= 2.2.7)
107
+ crack (>= 0.3.2)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ bundler (~> 1.0)
114
+ coveralls
115
+ httparty
116
+ jeweler (~> 1.8.7)
117
+ pry
118
+ rdoc (~> 3.12)
119
+ rspec
120
+ shoulda
121
+ shoulda-matchers
122
+ simplecov
123
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 David Fisher
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # GaExampleGem
2
+
3
+ [![Coverage Status](https://coveralls.io/repos/tibbon/ga-example-gem/badge.png)](https://coveralls.io/r/tibbon/ga-example-gem)
4
+
5
+ This Gem is just to demonstrate some patterns for creating, documenting and testing a Gem.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'ga_example_gem'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ga_example_gem
20
+
21
+ ## Usage
22
+
23
+ Setup a new instance:
24
+
25
+ ```ruby
26
+ client = GaExampleGem.configure do |config|
27
+ config.api_key = "your_api_key"
28
+ end
29
+ ```
30
+
31
+
32
+ Now make a request for an XKCD comic:
33
+
34
+ ```ruby
35
+ # Returns JSON of the first XKCD comic
36
+ client.get_xkcd(1)
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ga_example_gem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ga_example_gem"
8
+ spec.version = GaExampleGem::VERSION
9
+ spec.authors = ["David Fisher"]
10
+ spec.email = ["tibbon@gmail.com"]
11
+ spec.description = %q{An example gem}
12
+ spec.summary = %q{Makes requests to APIs and has tests.}
13
+ spec.homepage = "https://github.com/tibbon/ga-example-gem"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "httparty"
25
+ end
@@ -0,0 +1,28 @@
1
+ # Require files in your internal folder
2
+ require 'ga_example_gem/client'
3
+
4
+ # This is our GaExampleGem namespace
5
+ # for our gem
6
+ module GaExampleGem
7
+ class << self
8
+ # Alias for GaExampleGem::Client.new
9
+ def new
10
+ @client ||= GaExampleGem::Client.new
11
+ end
12
+
13
+ # Delegate to GaExampleGem::Client
14
+ # This is a weird trick that allows for calling
15
+ # on methods without calling .new first
16
+ def method_missing(method, *args, &block)
17
+ return super unless new.respond_to?(method)
18
+ new.send(method, *args, &block)
19
+ end
20
+
21
+
22
+ # This is used for the method_missing to see
23
+ # if a new client would respond to a method
24
+ def respond_to?(method, include_private=false)
25
+ new.respond_to?(method, include_private) || super(method, include_private)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+ require 'httparty'
3
+ require 'ga_example_gem/configuration'
4
+
5
+ module GaExampleGem
6
+
7
+ # This is our client that we can initialize with
8
+ # GaExampleGem.new
9
+ class Client
10
+ include GaExampleGem::Configuration
11
+ include HTTParty
12
+
13
+ # This resets our API keys when it is initialized
14
+ def initialize
15
+ reset
16
+ end
17
+
18
+ # This method gets the JSON for a single XKCD comic
19
+ # by number
20
+ def get_xkcd(number)
21
+ JSON.parse self.class.get("http://xkcd-unofficial-api.herokuapp.com/xkcd?num=#{number}")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module GaExampleGem
2
+
3
+ # This is the configuration module that
4
+ # allows us to setup an api_key
5
+ # using a pattern close to the Twitter or MtGox gem
6
+ module Configuration
7
+
8
+ # This is our API key. We aren't really using it
9
+ # anywhere, but you could imagine using it
10
+ # with HTTP requests
11
+ attr_accessor :api_key
12
+
13
+ # This yields a block that can be iterated on
14
+ # Its useful for being able to set values to the
15
+ # attr_accessor
16
+ def configure
17
+ yield self
18
+ end
19
+
20
+ # This reset our API key and is called when the
21
+ # client is initialized
22
+ def reset
23
+ self.api_key = nil
24
+ self
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module GaExampleGem
2
+
3
+ # This sets the version of our gem
4
+ # Its a bit complex, but check out Semantic Versionining
5
+ # http://semver.org/
6
+ VERSION = "0.0.1"
7
+ end
@@ -0,0 +1 @@
1
+ [{"id":1,"month":1,"num":1,"link":"","year":2006,"news":"","safe_title":"Barrel - Part 1","transcript":"[[A boy sits in a barrel which is floating in an ocean.]]\nBoy: I wonder where I'll float next?\n[[The barrel drifts into the distance. Nothing else can be seen.]]\n{{Alt: Don't we all.}}","title_text":null,"alt":"Don't we all.","img":"http://imgs.xkcd.com/comics/barrel_cropped_(1).jpg","title":"Barrel - Part 1","day":1,"created_at":"2013-11-25T16:57:20.568Z","updated_at":"2013-11-25T16:57:20.568Z"}]
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe GaExampleGem::Client do
4
+ before do
5
+ @client = GaExampleGem::Client.new
6
+ @client.configure do |config|
7
+ config.api_key = "its a secret to everybody"
8
+ end
9
+ end
10
+
11
+ describe '#get_xkcd' do
12
+ before do
13
+ stub_request(:get, 'http://xkcd-unofficial-api.herokuapp.com/xkcd?num=1').
14
+ to_return(body: fixture('single_xkcd.json'))
15
+ end
16
+
17
+ it "fetchs a single xkcd webcomic" do
18
+ comic = @client.get_xkcd(1)
19
+ expect(a_request(:get, 'http://xkcd-unofficial-api.herokuapp.com/xkcd?num=1')).to have_been_made
20
+ expect(comic.first["title"]).to eq "Barrel - Part 1"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ # Nothing needed in here. Already has full test coverage
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe GaExampleGem do
4
+ describe '.new' do
5
+ it "returns a GaExampleGem::Client" do
6
+ expect(GaExampleGem.new).to be_a GaExampleGem::Client
7
+ end
8
+ end
9
+
10
+ describe ".configure" do
11
+ it "sets api_key" do
12
+ GaExampleGem.configure do |config|
13
+ config.api_key = "its a secret to everybody"
14
+ end
15
+
16
+ expect(GaExampleGem.api_key).to eq "its a secret to everybody"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
10
+ require 'ga_example_gem'
11
+ require 'rspec'
12
+ require 'webmock/rspec'
13
+ require 'json'
14
+
15
+ RSpec.configure do |config|
16
+ config.order = 'random'
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+ end
21
+
22
+ def fixture_path
23
+ File.expand_path('../fixtures', __FILE__)
24
+ end
25
+
26
+ def fixture(file)
27
+ File.new(fixture_path + '/' + file)
28
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ga_example_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Fisher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: httparty
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: An example gem
79
+ email:
80
+ - tibbon@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .document
86
+ - .gitignore
87
+ - .rspec
88
+ - .travis.yml
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - ga-example-gem.gemspec
95
+ - lib/ga_example_gem.rb
96
+ - lib/ga_example_gem/client.rb
97
+ - lib/ga_example_gem/configuration.rb
98
+ - lib/ga_example_gem/version.rb
99
+ - spec/fixtures/single_xkcd.json
100
+ - spec/ga_example_gem/client_spec.rb
101
+ - spec/ga_example_gem/configuration_spec.rb
102
+ - spec/ga_example_gem_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/tibbon/ga-example-gem
105
+ licenses:
106
+ - MIT
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.25
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Makes requests to APIs and has tests.
129
+ test_files:
130
+ - spec/fixtures/single_xkcd.json
131
+ - spec/ga_example_gem/client_spec.rb
132
+ - spec/ga_example_gem/configuration_spec.rb
133
+ - spec/ga_example_gem_spec.rb
134
+ - spec/spec_helper.rb
135
+ has_rdoc: