rippy_rules 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 +21 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +52 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/lib/rippy_rules/rippy_rules.rb +40 -0
- data/lib/rippy_rules/version.rb +3 -0
- data/lib/rippy_rules.rb +6 -0
- data/rippy_rules.gemspec +30 -0
- data/spec/config.yml.example +2 -0
- data/spec/lib/rippy_rules/rippy_rules_spec.rb +56 -0
- data/spec/spec_helper.rb +36 -0
- metadata +174 -0
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
spec/config.yml
|
16
|
+
spec/fixtures/cassette_library/*
|
17
|
+
|
18
|
+
# YARD artifacts
|
19
|
+
.yardoc
|
20
|
+
_yardoc
|
21
|
+
doc/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rippy_rules (0.0.1)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.2)
|
11
|
+
crack (0.3.1)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
guard (1.4.0)
|
14
|
+
listen (>= 0.4.2)
|
15
|
+
thor (>= 0.14.6)
|
16
|
+
guard-rspec (2.0.0)
|
17
|
+
guard (>= 1.1)
|
18
|
+
rspec (~> 2.11)
|
19
|
+
httparty (0.9.0)
|
20
|
+
multi_json (~> 1.0)
|
21
|
+
multi_xml
|
22
|
+
listen (0.5.3)
|
23
|
+
metaclass (0.0.1)
|
24
|
+
mocha (0.12.6)
|
25
|
+
metaclass (~> 0.0.1)
|
26
|
+
multi_json (1.3.6)
|
27
|
+
multi_xml (0.5.1)
|
28
|
+
rspec (2.11.0)
|
29
|
+
rspec-core (~> 2.11.0)
|
30
|
+
rspec-expectations (~> 2.11.0)
|
31
|
+
rspec-mocks (~> 2.11.0)
|
32
|
+
rspec-core (2.11.1)
|
33
|
+
rspec-expectations (2.11.3)
|
34
|
+
diff-lcs (~> 1.1.3)
|
35
|
+
rspec-mocks (2.11.3)
|
36
|
+
thor (0.16.0)
|
37
|
+
vcr (2.2.5)
|
38
|
+
webmock (1.8.11)
|
39
|
+
addressable (>= 2.2.7)
|
40
|
+
crack (>= 0.1.7)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
guard
|
47
|
+
guard-rspec
|
48
|
+
mocha
|
49
|
+
rippy_rules!
|
50
|
+
rspec
|
51
|
+
vcr
|
52
|
+
webmock
|
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec',:output => 'specs',:bundler => true,all_on_start: false do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Magnus Skog
|
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,48 @@
|
|
1
|
+
# RippyRules
|
2
|
+
|
3
|
+
A Ruby wrapper for the What.cd JSON API
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rippy_rules'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rippy_rules
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Initialize a client like so:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client = RippyRules::Client.new(your_whatcd_username, your_whatcd_password)
|
25
|
+
```
|
26
|
+
You can then run any command in the API by calling it's corresponding method. Each method will return a hash
|
27
|
+
|
28
|
+
## API Documentation
|
29
|
+
The documentation for the API methods can be found in the What.cd wiki
|
30
|
+
|
31
|
+
## Examples
|
32
|
+
|
33
|
+
Searching for an artist
|
34
|
+
```ruby
|
35
|
+
client = RippyRules::Client.new(your_whatcd_username, your_whatcd_password)
|
36
|
+
results = client.browse({searchstr: 'Bruce Springsteen'})
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
To contribute to RippyRules, you must have a What.cd account. I do not have one and I do not know how to acquire one.
|
42
|
+
If you don't have an account, the specs will not run
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module RippyRules
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
base_uri "https://what.cd"
|
5
|
+
maintain_method_across_redirects
|
6
|
+
format :json
|
7
|
+
|
8
|
+
def initialize(username, password)
|
9
|
+
@username = username
|
10
|
+
@password = password
|
11
|
+
authenticate
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *params)
|
15
|
+
raise APIError unless params.first.is_a?(Hash)
|
16
|
+
perform_request(method.to_s,params.first)
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform_request(method, query={})
|
20
|
+
self.class.get("/ajax.php?action=#{method}", :query => query)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def authenticate
|
26
|
+
body = {:username => @username, :password => @password, :keeplogged => 1}
|
27
|
+
response = self.class.post('/login.php', :body => body, :follow_redirects => false)
|
28
|
+
raise AuthenticationError if response.headers['set-cookie'].nil?
|
29
|
+
cookies(response.headers['set-cookie'])
|
30
|
+
end
|
31
|
+
|
32
|
+
def cookies(cookie)
|
33
|
+
cookie_jar = HTTParty::CookieHash.new
|
34
|
+
cookie_jar.add_cookies cookie
|
35
|
+
self.class.cookies cookie_jar
|
36
|
+
end
|
37
|
+
end
|
38
|
+
class AuthenticationError < StandardError; end
|
39
|
+
class APIError < StandardError; end
|
40
|
+
end
|
data/lib/rippy_rules.rb
ADDED
data/rippy_rules.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rippy_rules/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rippy_rules"
|
8
|
+
gem.version = RippyRules::VERSION
|
9
|
+
gem.authors = ["Magnus Skog"]
|
10
|
+
gem.email = ["mrcheese0@gmail.com"]
|
11
|
+
gem.description = "A Ruby library for the What.cd api"
|
12
|
+
gem.summary = "Ruby What.cd API"
|
13
|
+
gem.homepage = %q{https://github.com/MrCheese/rippy_rules}
|
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.name = "rippy_rules"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = RippyRules::VERSION
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'mocha'
|
24
|
+
gem.add_development_dependency 'guard'
|
25
|
+
gem.add_development_dependency 'guard-rspec'
|
26
|
+
gem.add_development_dependency 'vcr'
|
27
|
+
gem.add_development_dependency 'webmock'
|
28
|
+
|
29
|
+
gem.add_runtime_dependency 'httparty'
|
30
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RippyRules::Client do
|
4
|
+
use_vcr_cassette :record => :new_episodes, :match_requests_on => [:body, :uri]
|
5
|
+
|
6
|
+
it "includes HTTParty" do
|
7
|
+
rippy_rules = RippyRules::Client.new(WHATCD_USERNAME,WHATCD_PASSWORD)
|
8
|
+
rippy_rules.kind_of?(HTTParty).should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
context "when given valid authentication information" do
|
13
|
+
it "authenticates the user" do
|
14
|
+
rippy_rules = RippyRules::Client.new(WHATCD_USERNAME, WHATCD_PASSWORD)
|
15
|
+
rippy_rules.class.cookies[:session].nil?.should == false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when the authentication fails" do
|
20
|
+
it "throws an AuthenticationError" do
|
21
|
+
expect{rippy_rules = RippyRules::Client.new('foo', 'bar')}.to raise_error(RippyRules::AuthenticationError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#method_missing?" do
|
27
|
+
let(:rippy_rules){RippyRules::Client.new(WHATCD_USERNAME, WHATCD_PASSWORD)}
|
28
|
+
context "when given an action and a hash" do
|
29
|
+
it "performs a request with the method name as the request type" do
|
30
|
+
method = 'top10'
|
31
|
+
params = {:type => :users}
|
32
|
+
results = rippy_rules.send(method.to_sym, params)
|
33
|
+
results['response'].first['results'].size == 10
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when the first parameter is not a hash" do
|
38
|
+
it "throws an APIError" do
|
39
|
+
method = 'eatmyshorts'
|
40
|
+
param = 'foo'
|
41
|
+
expect{rippy_rules.send(method.to_sym,param)}.to raise_error(RippyRules::APIError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#perform_request" do
|
47
|
+
let(:rippy_rules){RippyRules::Client.new(WHATCD_USERNAME, WHATCD_PASSWORD)}
|
48
|
+
it "performs a GET request with the correct parameters" do
|
49
|
+
method = 'top10'
|
50
|
+
query = {:limit => 10, :type => :torrents}
|
51
|
+
rippy_rules.class.expects(:get).with("/ajax.php?action=top10", :query => query)
|
52
|
+
rippy_rules.send(method.to_sym, query)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'rippy_rules'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'vcr'
|
5
|
+
require "yaml"
|
6
|
+
|
7
|
+
SPEC_DIR = File.dirname(__FILE__)
|
8
|
+
lib_path = File.expand_path("#{SPEC_DIR}/../lib")
|
9
|
+
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
10
|
+
|
11
|
+
|
12
|
+
if File.exists?("spec/config.yml") == false
|
13
|
+
puts "Error. Please make sure that 'spec/config.yml' exists with the correct values before running the specs. See example file"
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
config = YAML::load_file("spec/config.yml")
|
18
|
+
WHATCD_USERNAME = config['whatcd_username']
|
19
|
+
WHATCD_PASSWORD = config['whatcd_password']
|
20
|
+
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.color_enabled = true
|
24
|
+
config.formatter = 'documentation'
|
25
|
+
config.mock_framework = :mocha
|
26
|
+
config.extend VCR::RSpec::Macros
|
27
|
+
end
|
28
|
+
|
29
|
+
VCR.configure do |c|
|
30
|
+
c.cassette_library_dir = 'spec/fixtures/cassette_library'
|
31
|
+
c.hook_into :webmock
|
32
|
+
c.default_cassette_options = { :record => :none}
|
33
|
+
|
34
|
+
c.filter_sensitive_data('<WHATCD_USERNAME>') { WHATCD_USERNAME}
|
35
|
+
c.filter_sensitive_data('<WHATCD_PASSWORD>') { WHATCD_PASSWORD}
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rippy_rules
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Magnus Skog
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mocha
|
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: guard
|
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: guard-rspec
|
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: vcr
|
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: webmock
|
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: httparty
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
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: A Ruby library for the What.cd api
|
127
|
+
email:
|
128
|
+
- mrcheese0@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- Guardfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- lib/rippy_rules.rb
|
141
|
+
- lib/rippy_rules/rippy_rules.rb
|
142
|
+
- lib/rippy_rules/version.rb
|
143
|
+
- rippy_rules.gemspec
|
144
|
+
- spec/config.yml.example
|
145
|
+
- spec/lib/rippy_rules/rippy_rules_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
homepage: https://github.com/MrCheese/rippy_rules
|
148
|
+
licenses: []
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.8.24
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: Ruby What.cd API
|
171
|
+
test_files:
|
172
|
+
- spec/config.yml.example
|
173
|
+
- spec/lib/rippy_rules/rippy_rules_spec.rb
|
174
|
+
- spec/spec_helper.rb
|