foauth 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/.gitignore ADDED
@@ -0,0 +1,17 @@
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
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in foauth.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Chris Mytton
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,62 @@
1
+ # Foauth
2
+
3
+ [foauth.org][foauth] Ruby client built on top of [faraday][].
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'foauth'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install foauth
20
+
21
+ ## Usage
22
+
23
+ Create a new client passing in your [foauth][] email and password.
24
+
25
+ ```ruby
26
+ client = Foauth.new('bob@example.org', 'secret')
27
+ ```
28
+
29
+ When you make a request to one of the supported [foauth services][] the url will automatically be converted to a
30
+ foauth url using the hostname and the path.
31
+
32
+ ```ruby
33
+ response = client.get('https://api.twitter.com/1/statuses/user_timeline.json')
34
+ # An authenticated request is made to https://foauth.org/api.twitter.com/1/statuses/user_timeline.json
35
+
36
+ puts response.success? # true
37
+ puts response.body # [{"created_at":"Mon Dec 31 23:59:13 +0000 2012"...
38
+ puts response.status # 200
39
+ ```
40
+
41
+ The `client` returned is an instance of `Faraday::Connection` and the
42
+ `response` is an instance of `Faraday::Response`. See [faraday][] for
43
+ more information.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+
53
+ ## Credits
54
+
55
+ Inspired by [requests-foauth][] by @kennethreitz.
56
+
57
+ Copyright (c) Chris Mytton
58
+
59
+ [foauth]: https://foauth.org
60
+ [faraday]: https://github.com/lostisland/faraday
61
+ [requests-foauth]: https://github.com/kennethreitz/requests-foauth
62
+ [foauth services]: https://foauth.org/services/
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run the specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
data/foauth.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foauth/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "foauth"
8
+ gem.version = Foauth::VERSION
9
+ gem.authors = ["Chris Mytton"]
10
+ gem.email = ["self@hecticjeff.net"]
11
+ gem.description = %q{foauth.org ruby client}
12
+ gem.summary = %q{Transparently make authenticated API requests via foauth.org}
13
+ gem.homepage = "https://github.com/hecticjeff/foauth"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'faraday', '>= 0.8'
21
+ gem.add_development_dependency 'rspec', '>= 2.11'
22
+ end
@@ -0,0 +1,11 @@
1
+ require 'faraday'
2
+
3
+ module Foauth
4
+ class RewriteMiddleware < Faraday::Middleware
5
+ def call(env)
6
+ url = env[:url]
7
+ env[:url] = URI.parse("https://foauth.org/#{url.host}#{url.path}")
8
+ @app.call(env)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Foauth
2
+ VERSION = "0.0.1"
3
+ end
data/lib/foauth.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'faraday'
2
+
3
+ require 'foauth/version'
4
+ require 'foauth/rewrite_middleware'
5
+
6
+ module Foauth
7
+ def self.new(email, password)
8
+ Faraday.new do |builder|
9
+ builder.request :basic_auth, email, password
10
+ builder.use RewriteMiddleware
11
+ builder.adapter Faraday.default_adapter
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foauth do
4
+ let(:client) { Foauth.new('bob@example.org', '123') }
5
+ let(:response) { client.get('https://api.twitter.com/1/statuses/user_timeline.json') }
6
+ let(:auth) { response.env[:request_headers]['Authorization'] }
7
+
8
+ before do
9
+ client.adapter :test do |stub|
10
+ stub.get('/api.twitter.com/1/statuses/user_timeline.json') { [200, {}, '{}'] }
11
+ end
12
+ end
13
+
14
+ it "authenticates with email and password" do
15
+ auth.should == 'Basic Ym9iQGV4YW1wbGUub3JnOjEyMw=='
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foauth::RewriteMiddleware do
4
+ let(:conn) do
5
+ conn = Faraday.new do |builder|
6
+ builder.use Foauth::RewriteMiddleware
7
+ builder.adapter :test do |stub|
8
+ stub.get('/api.twitter.com/1/statuses/user_timeline.json') {[ 200, {}, '{}' ]}
9
+ end
10
+ end
11
+ end
12
+
13
+ it "changes the url for an intercepted request" do
14
+ res = conn.get('https://api.twitter.com/1/statuses/user_timeline.json')
15
+ expect(res.env[:url].to_s).to eq 'https://foauth.org/api.twitter.com/1/statuses/user_timeline.json'
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'foauth'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Mytton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0.8'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
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: '2.11'
46
+ description: foauth.org ruby client
47
+ email:
48
+ - self@hecticjeff.net
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - foauth.gemspec
60
+ - lib/foauth.rb
61
+ - lib/foauth/rewrite_middleware.rb
62
+ - lib/foauth/version.rb
63
+ - spec/client_spec.rb
64
+ - spec/middleware_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: https://github.com/hecticjeff/foauth
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Transparently make authenticated API requests via foauth.org
90
+ test_files:
91
+ - spec/client_spec.rb
92
+ - spec/middleware_spec.rb
93
+ - spec/spec_helper.rb