faraday-cookie_jar 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in faraday-cookie_jar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tatsuhiko Miyagawa
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,38 @@
1
+ # Faraday::CookieJar
2
+
3
+ Faraday middleware to manage client-side cookies
4
+
5
+ ## Description
6
+
7
+ This gem is a piece of Faraday middleware that adds client-side Cookies management, using [cookirjar gem](https://github.com/dwaite/cookiejar).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'faraday-cookie_jar'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install faraday-cookie_jar
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'faraday-cookie_jar'
27
+
28
+ conn = Faraday.new(:url => "http://example.com") do |builder|
29
+ builder.use :cookie_jar
30
+ end
31
+
32
+ conn.get "/foo" # gets cookie
33
+ conn.get "/bar" # sends cookie
34
+ ```
35
+
36
+ ## Author
37
+
38
+ Tatsuhiko Miyagawa
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'faraday-cookie_jar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "faraday-cookie_jar"
8
+ spec.version = Faraday::CookieJarVersion::VERSION
9
+ spec.authors = ["Tatsuhiko Miyagawa"]
10
+ spec.email = ["miyagawa@bulknews.net"]
11
+ spec.description = %q{Cookie jar middleware for Faraday}
12
+ spec.summary = %q{Manages client-side cookie jar for Faraday HTTP client}
13
+ spec.homepage = "https://github.com/miyagawa/faraday-cookie_jar"
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_dependency "faraday", ">= 0.7.4"
22
+ spec.add_dependency "cookiejar"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "sinatra"
28
+ spec.add_development_dependency "sham_rack"
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'faraday/cookie_jar'
2
+ require 'faraday-cookie_jar/version'
@@ -0,0 +1,5 @@
1
+ module Faraday
2
+ module CookieJarVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require "faraday"
2
+ require "cookiejar"
3
+
4
+ module Faraday
5
+ class CookieJar < Faraday::Middleware
6
+ def initialize(app, options = {})
7
+ super(app)
8
+ @jar = ::CookieJar::Jar.new
9
+ end
10
+
11
+ def call(env)
12
+ cookie = @jar.get_cookie_header(env[:url])
13
+ unless cookie.empty?
14
+ env[:request_headers]["Cookie"] = cookie
15
+ end
16
+
17
+ @app.call(env).on_complete do |res|
18
+ @jar.set_cookies_from_headers(env[:url], res[:response_headers])
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ if Faraday.respond_to? :register_middleware
25
+ Faraday.register_middleware :cookie_jar => lambda { Faraday::CookieJar }
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Faraday::CookieJar do
4
+ let(:conn) { Faraday.new(:url => 'http://faraday.example.com') }
5
+
6
+ before do
7
+ conn.use :cookie_jar
8
+ conn.adapter :net_http # for sham_rock
9
+ end
10
+
11
+ it 'get default cookie' do
12
+ conn.get('/default')
13
+ conn.get('/dump').body.should == 'foo=bar'
14
+ end
15
+
16
+ it 'does not send cookies to wrong path' do
17
+ conn.get('/path')
18
+ conn.get('/dump').body.should_not == 'foo=bar'
19
+ end
20
+
21
+ it 'expires cookie' do
22
+ conn.get('/expires')
23
+ conn.get('/dump').body.should == 'foo=bar'
24
+ sleep 2
25
+ conn.get('/dump').body.should_not == 'foo=bar'
26
+ end
27
+ end
28
+
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'faraday-cookie_jar'
3
+
4
+ require 'sham_rack'
5
+ require_relative 'support/fake_app'
6
+
7
+ ShamRack.at('faraday.example.com').rackup do
8
+ run FakeApp
9
+ end
@@ -0,0 +1,19 @@
1
+ require 'sinatra'
2
+
3
+ class FakeApp < Sinatra::Application
4
+ get '/dump' do
5
+ "foo=#{request.cookies['foo']}"
6
+ end
7
+
8
+ get '/default' do
9
+ response.set_cookie "foo", :value => "bar"
10
+ end
11
+
12
+ get '/path' do
13
+ response.set_cookie "foo", :value => "bar", :path => "/path"
14
+ end
15
+
16
+ get '/expires' do
17
+ response.set_cookie "foo", :value => "bar", :expires => Time.now + 1
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-cookie_jar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tatsuhiko Miyagawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-11 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.7.4
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.7.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: cookiejar
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
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: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
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: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
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
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: sinatra
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sham_rack
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Cookie jar middleware for Faraday
127
+ email:
128
+ - miyagawa@bulknews.net
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - faraday-cookie_jar.gemspec
139
+ - lib/faraday-cookie_jar.rb
140
+ - lib/faraday-cookie_jar/version.rb
141
+ - lib/faraday/cookie_jar.rb
142
+ - spec/faraday-cookie_jar/cookie_jar_spec.rb
143
+ - spec/spec_helper.rb
144
+ - spec/support/fake_app.rb
145
+ homepage: https://github.com/miyagawa/faraday-cookie_jar
146
+ licenses:
147
+ - MIT
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 1.8.23
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: Manages client-side cookie jar for Faraday HTTP client
170
+ test_files:
171
+ - spec/faraday-cookie_jar/cookie_jar_spec.rb
172
+ - spec/spec_helper.rb
173
+ - spec/support/fake_app.rb