mechanize-cookie_store 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a51392cdff41056325f7792b45956555f2769bb9dc6184a5bc83edeeee00d083
4
+ data.tar.gz: 99ce99c06cd142209a57c725ed9df72af97c1b5f8941d78a920c5bcf8205a042
5
+ SHA512:
6
+ metadata.gz: bb5d2b8610d78cd404d726ebceb9a9c5e3fd7477b33e81b3564d608066df9aa13903f71ec248485c250a91603a7a3e51655fcffb2beeeb3dfde3698146ec8bfa
7
+ data.tar.gz: 120b9be8e427d293cbbb4f60ca44bc2757b4fdd05c488928bffba7d9e7f51545572187ace7837b49dbcc53e8810e7b5d9aabad7f5d51803974b78692ac01274e
@@ -0,0 +1,21 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # byebug command history
14
+ .byebug_history
15
+
16
+ # for a library or gem, you might want to ignore these files since the code is
17
+ # intended to run in multiple environments; otherwise, check them in:
18
+ Gemfile.lock
19
+ gemfiles/*.gemfile.lock
20
+ .ruby-version
21
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
6
+ services:
7
+ - redis-server
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hello@cedarcode.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mechanize-cookie_store.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 hello@cedarcode.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,104 @@
1
+ # Mechanize::CookieStore
2
+
3
+ [![Build Status](https://travis-ci.org/cedarcode/mechanize-cookie_store.svg?branch=master)](https://travis-ci.org/cedarcode/mechanize-cookie_store)
4
+
5
+ mechanize-cookie_store is an extension to [Mechanize gem](https://github.com/sparklemotion/mechanize) that allow you to persist the Mechanize agent cookie set, in a smarter way than serialized or plain files in the server's system. This allows you to share your cookies across multiple server instances, among other benefits.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mechanize-cookie_store'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mechanize-cookie_store
22
+
23
+ ## Configuration
24
+
25
+ For *Rails* applications you can create `config/initializers/mechanize-cookie_store.rb` and provide the necessary
26
+ configuration params to access your desired persistance method.
27
+
28
+ If your not using Rails, you just need to make sure to run the same configuration code before using Mechanize.
29
+
30
+ Please see below the available built-in stores and their specific configurations:
31
+
32
+ ***Currently, the only supported store is Redis.***
33
+
34
+ ### For Redis
35
+
36
+ ```ruby
37
+ Mechanize::CookieStore.configure do |config|
38
+ config.connection_params = {
39
+ url: "your-redis-url",
40
+ namespace: "your-redis-namespace" # optional
41
+ }
42
+ end
43
+ ```
44
+
45
+ - `url` must have a valid redis server url
46
+ - `namespace` parameter is optional, default namespace is `mechanize_cookies`
47
+
48
+
49
+ ## Usage
50
+
51
+ After configuring it, usage looks pretty similar to the way you would use
52
+ mechanize without this gem.
53
+
54
+ Instantiate a mechanize session and use it:
55
+
56
+ ```ruby
57
+ agent = Mechanize.new
58
+
59
+ agent.get("https://www.google.com")
60
+ ```
61
+
62
+
63
+ Then `save` or`load` your cookie_jar the same way you would do it without `mechanize-cookie_store`.
64
+
65
+ ```ruby
66
+ agent.cookie_jar.save # to persist cookies to storage
67
+
68
+ agent.cookie_jar.load # to load back back into the agent from storage
69
+ ```
70
+
71
+ Or use if you want to load specific cookie set you can pass to `load` the options
72
+ `domain`, `path` and `name` like this:
73
+
74
+ ```ruby
75
+ agent.cookie_jar.load(domain: "example.com", path: "/mypath", name: "myCookie")
76
+ ```
77
+
78
+ Please note, that these options correpond to the fields of the [HTTP::Cookie](https://github.com/sparklemotion/http-cookie/blob/v1.0.3/lib/http/cookie.rb#L27) class, an inherited dependency from Mechanize.
79
+
80
+
81
+ ## Dependencies
82
+
83
+ This gem depends on:
84
+
85
+ - [Mechanize](https://github.com/sparklemotion/mechanize)
86
+ - [Redis Namespace](https://github.com/resque/redis-namespace)
87
+
88
+ ## Contributing
89
+
90
+ 1. Fork it ( https://github.com/cedarcode/mechanize=cookie_store/ )
91
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create a new Pull Request
95
+
96
+ To run the test suite, make sure you have Redis server running in `localhost:6379`. Then just run `bundle exec rake`
97
+
98
+ ## License
99
+
100
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
101
+
102
+ ## Code of Conduct
103
+
104
+ Everyone interacting in the Mechanize::CookieStore project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cedarcode/mechanize-cookie_store/blob/master/CODE_OF_CONDUCT.md).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mechanize/cookie_store"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require "mechanize"
2
+ require "mechanize/cookie_store/version"
3
+ require "mechanize/cookie_store/cookie_jar"
4
+ require "mechanize/cookie_store/redis"
5
+
6
+ module Mechanize::CookieStore
7
+
8
+ class << self
9
+
10
+ attr_accessor :connection_params
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ module Mechanize::CookieStore
2
+ module CookieJar
3
+
4
+ def save
5
+ each do |cookie|
6
+ ::Mechanize::CookieStore::Redis.save(cookie)
7
+ end
8
+ end
9
+
10
+ def load(options = {})
11
+ ::Mechanize::CookieStore::Redis.all(options).each do |cookie|
12
+ add(cookie)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+
19
+ class Mechanize::CookieJar
20
+ prepend Mechanize::CookieStore::CookieJar
21
+ end
@@ -0,0 +1,52 @@
1
+ require "redis-namespace"
2
+
3
+ class Mechanize::CookieStore::Redis
4
+
5
+ DEFAULT_NAMESPACE = "mechanize_cookies".freeze
6
+
7
+ def self.connection
8
+ return @store_connection if @store_connection
9
+
10
+ namespace = Mechanize::CookieStore.connection_params[:namespace] || DEFAULT_NAMESPACE
11
+ redis_connection = ::Redis.new(Mechanize::CookieStore.connection_params)
12
+
13
+ @store_connection = ::Redis::Namespace.new(namespace, redis: redis_connection)
14
+ end
15
+
16
+ def self.all(options = {})
17
+ normalized_keys(options).each_with_object([]) do |key, cookies|
18
+ serialized_cookie = connection.get(key)
19
+
20
+ if serialized_cookie
21
+ cookie = Marshal.load(serialized_cookie)
22
+
23
+ unless cookie_expired?(cookie)
24
+ cookies << cookie
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.save(cookie)
31
+ return if cookie_expired?(cookie)
32
+
33
+ key = "#{cookie.domain}:#{cookie.path}:#{cookie.name}"
34
+
35
+ connection.set(key, Marshal.dump(cookie)) == "OK"
36
+ end
37
+
38
+ def self.cookie_expired?(cookie)
39
+ cookie.expires && cookie.expires < Time.now.utc ||
40
+ cookie.created_at && cookie.max_age &&
41
+ cookie.created_at + cookie.max_age < Time.now.utc
42
+ end
43
+
44
+ def self.normalized_keys(options = {})
45
+ domain = options[:domain] || "*"
46
+ path = options[:path] || "*"
47
+ name = options[:name] || "*"
48
+
49
+ connection.keys("#{domain}:#{path}:#{name}")
50
+ end
51
+
52
+ end
@@ -0,0 +1,5 @@
1
+ class Mechanize
2
+ module CookieStore
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require "mechanize/cookie_store/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "mechanize-cookie_store"
9
+ spec.version = Mechanize::CookieStore::VERSION
10
+ spec.authors = ["Braulio Martinez"]
11
+ spec.email = ["braulio@cedarcode.com"]
12
+
13
+ spec.summary = "A Mechanize extension that allows cookies to be saved in more advanced stores than serialized filesystem files."
14
+ spec.homepage = "https://github.com/cedarcode/mechanize-cookie_store"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "mechanize", "~> 2.7"
24
+ spec.add_dependency "redis-namespace", "~> 1.6"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "byebug"
30
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mechanize-cookie_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Braulio Martinez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis-namespace
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - braulio@cedarcode.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/mechanize/cookie_store.rb
115
+ - lib/mechanize/cookie_store/cookie_jar.rb
116
+ - lib/mechanize/cookie_store/redis.rb
117
+ - lib/mechanize/cookie_store/version.rb
118
+ - mechanize-cookie_store.gemspec
119
+ homepage: https://github.com/cedarcode/mechanize-cookie_store
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.7.6
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: A Mechanize extension that allows cookies to be saved in more advanced stores
143
+ than serialized filesystem files.
144
+ test_files: []