bring 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: 97d5eec883fe2e9e432dfe019281bde0a2d1994f
4
+ data.tar.gz: 1849980a27923652ee5eaec13c21abd5a7c4f828
5
+ SHA512:
6
+ metadata.gz: a32c9f8183a00f32d1d63449751e1f0445ae6d2828ca5bee4b8b0c98bf4941f1f617d7342d007255da94963feb4510e7f1e4a30b20a19647bfd7ded10922999f
7
+ data.tar.gz: 50f6f069b0c1ebee7ae5adeb587538377a9a27d7255a4d8256d0e72f45a541e391b40b0a1192aed984faabbb0d6133963446047575d38592dc0753d357612ae4
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/fixtures/vcr_cassettes
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bring.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Erlend Finvåg
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,43 @@
1
+ # Bring
2
+
3
+ [![Build Status](https://travis-ci.org/wepack/bring.png)](https://travis-ci.org/wepack/bring)
4
+
5
+ A simple ruby library for communicating with the Bring's APIs (see:
6
+ [developer.bring.com](http://developer.bring.com)).
7
+
8
+ *For now only the Postal Code API is supported.*
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'bring'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install bring
23
+
24
+ ## Usage
25
+
26
+ From the commandline:
27
+
28
+ $ bring postal_code 0190 no
29
+ OSLO
30
+
31
+ Or in Ruby:
32
+ ```ruby
33
+ require 'bring/postal_code'
34
+ Bring::PostalCode.new('0190', country: 'no).city # => 'OSLO'
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/bring ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bring/cli'
4
+ Bring::CLI.start
data/bring.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bring/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bring"
8
+ spec.version = Bring::VERSION
9
+ spec.authors = ["Erlend Finvåg"]
10
+ spec.email = ["erlend.finvag@gmail.com"]
11
+ spec.description = %q{A simple utility for Bring's APIs}
12
+ spec.summary = %q{Command line client and Ruby library for bring's APIs}
13
+ spec.homepage = "https://github.com/wepack/bring"
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 "rspec", "~> 2.14"
24
+ spec.add_development_dependency "vcr"
25
+
26
+ spec.add_runtime_dependency "thor"
27
+
28
+ spec.add_dependency "faraday", "~> 0.8.0"
29
+ spec.add_dependency "faraday_middleware"
30
+
31
+ spec.add_dependency "json" if RUBY_VERSION.start_with?('1.8')
32
+ end
@@ -0,0 +1,16 @@
1
+ require 'bring/configurator'
2
+ require 'faraday_middleware'
3
+
4
+ module Bring
5
+ class BaseRequest
6
+
7
+ private
8
+ def connection
9
+ @connection ||= Faraday.new(api_url) do |conn|
10
+ conn.request :json
11
+ conn.response :json, :content_type => /\bjson$/
12
+ conn.adapter Bring.config.faraday_adapter || Faraday.default_adapter
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/bring/cli.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'thor'
2
+
3
+ module Bring
4
+ class CLI < Thor
5
+ desc 'postal_code PNR', 'get city from PNR'
6
+ option :country, :default => 'no'
7
+ def postal_code(pnr)
8
+ require 'bring/postal_code'
9
+ puts PostalCode.new(pnr, :country => options[:country]).city
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'singleton'
2
+
3
+ module Bring
4
+ def self.config(&block)
5
+ config = Bring::Configurator.instance
6
+ yield config if block_given?
7
+
8
+ config
9
+ end
10
+
11
+ class Configurator
12
+ include Singleton
13
+
14
+ # Specify Faraday adapter or use `Faraday.default_adapter` by default.
15
+ attr_accessor :faraday_adapter
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require 'bring/base_request'
2
+
3
+ module Bring
4
+ class PostalCode < BaseRequest
5
+ @@cities = {}
6
+ attr_reader :postal_code, :country
7
+
8
+ def self.reset_cache!
9
+ @@cities.clear
10
+ end
11
+
12
+ def initialize(pnr, options = {})
13
+ @postal_code, @country = pnr, options[:country]
14
+ end
15
+
16
+ def city
17
+ @@cities[postal_code] ||= request.body['result']
18
+ end
19
+
20
+ private
21
+ def request
22
+ connection.get do |req|
23
+ req.params['pnr'] = postal_code
24
+ req.params['country'] = country
25
+ end
26
+ end
27
+
28
+ def api_url
29
+ 'http://fraktguide.bring.no/fraktguide/api/postalCode.json'.freeze
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Bring
2
+ VERSION = "0.0.1"
3
+ end
data/lib/bring.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'bring/version'
2
+ require 'bring/configurator'
3
+
4
+ module Bring
5
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'bring/base_request'
3
+
4
+ class MockRequest < Bring::BaseRequest
5
+ def api_url
6
+ 'http://example.org/foo.json'.freeze
7
+ end
8
+
9
+ def connection
10
+ super
11
+ end
12
+ end
13
+
14
+ describe Bring::BaseRequest do
15
+ let(:base_request) { MockRequest.new }
16
+
17
+ describe 'connection' do
18
+ it 'returns faraday connection' do
19
+ expect(base_request.connection).to be_a Faraday::Connection
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'bring/cli'
3
+
4
+ describe Bring::CLI, :vcr do
5
+ def invoke!(*args)
6
+ capture(:stdout) { Bring::CLI.start(args) }
7
+ end
8
+
9
+ describe 'postal_code' do
10
+ it 'displays city for pnr' do
11
+ expect(invoke! 'postal_code', '0190').to eq "OSLO\n"
12
+ end
13
+
14
+ it 'takes a country' do
15
+ arguments = %w[postal_code 12000 --country se]
16
+ expect(invoke!(*arguments)).to eq "Stockholm\n"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+ require 'bring/configurator'
3
+
4
+ describe Bring::Configurator do
5
+ let(:configurator) { Bring::Configurator.instance }
6
+
7
+ describe 'self.configuration' do
8
+ it 'returns self' do
9
+ expect(Bring.config).to be configurator
10
+ end
11
+
12
+ it 'takes a block' do
13
+ expect(configurator).to receive(:foo).and_return('bar')
14
+
15
+ Bring.config do |config|
16
+ expect(config.foo).to eq 'bar'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'bring/postal_code'
3
+
4
+ describe Bring::PostalCode do
5
+ describe 'city', :vcr do
6
+ before do
7
+ Bring::PostalCode.reset_cache!
8
+ end
9
+
10
+ it "fetches result from Bring's API" do
11
+ postal_code = Bring::PostalCode.new('0190')
12
+
13
+ expect(postal_code.city).to eq 'OSLO'
14
+ end
15
+
16
+ it "keeps result in memory" do
17
+ Bring::PostalCode.new('0190').city
18
+
19
+ expect { Bring::PostalCode.new('0190').city }.not_to raise_error
20
+ end
21
+
22
+ it 'fetches result for different countries' do
23
+ postal_code = Bring::PostalCode.new('12000', :country => 'se')
24
+
25
+ expect(postal_code.city).to eq 'Stockholm'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'vcr'
3
+
4
+ VCR.configure do |config|
5
+ config.cassette_library_dir =
6
+ File.expand_path('../fixtures/vcr_cassettes', __FILE__)
7
+
8
+ config.hook_into :faraday
9
+ config.configure_rspec_metadata!
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = "random"
18
+
19
+ # This will be default behaviour in RSpec 3
20
+ config.treat_symbols_as_metadata_keys_with_true_values = true
21
+
22
+ def capture(stream)
23
+ begin
24
+ stream = stream.to_s
25
+ eval "$#{stream} = StringIO.new"
26
+ yield
27
+ result = eval("$#{stream}").string
28
+ ensure
29
+ eval("$#{stream} = #{stream.upcase}")
30
+ end
31
+
32
+ result
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Erlend Finvåg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
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: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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.8.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.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
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 simple utility for Bring's APIs
112
+ email:
113
+ - erlend.finvag@gmail.com
114
+ executables:
115
+ - bring
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - .travis.yml
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/bring
127
+ - bring.gemspec
128
+ - lib/bring.rb
129
+ - lib/bring/base_request.rb
130
+ - lib/bring/cli.rb
131
+ - lib/bring/configurator.rb
132
+ - lib/bring/postal_code.rb
133
+ - lib/bring/version.rb
134
+ - spec/bring/base_request_spec.rb
135
+ - spec/bring/cli_spec.rb
136
+ - spec/bring/configurator_spec.rb
137
+ - spec/bring/postal_code_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: https://github.com/wepack/bring
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.0.3
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Command line client and Ruby library for bring's APIs
163
+ test_files:
164
+ - spec/bring/base_request_spec.rb
165
+ - spec/bring/cli_spec.rb
166
+ - spec/bring/configurator_spec.rb
167
+ - spec/bring/postal_code_spec.rb
168
+ - spec/spec_helper.rb