assonnato 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/assonnato.rb +21 -0
- data/lib/assonnato/assonnato.rb +11 -0
- data/lib/assonnato/exception.rb +13 -0
- data/lib/assonnato/parser.rb +30 -0
- data/lib/assonnato/request.rb +43 -0
- data/lib/assonnato/type/episode.rb +25 -0
- data/lib/assonnato/type/show.rb +34 -0
- data/lib/assonnato/version.rb +13 -0
- data/spec/episode_spec.rb +30 -0
- data/spec/show_spec.rb +38 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c66c6688d50418b551f84148d33c39344d523d4
|
4
|
+
data.tar.gz: 2977ce2fc199a018961e4ebfd1182920d0c304b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 730bb6f8aa0d3740a0513d8af14ce69b1e46c6cbbbd5625d177264c37a5861caed886a972ec74d8164fb39ceddef0ba42618851d59c36a2ba4fa1d72316629de
|
7
|
+
data.tar.gz: 1d158e97bfb288151cb3468a6635d477d1526b83760ddeebf441f1e5976cadc400c5f527bf52571aed5518bd3be874fa79c24d504a74b48dfca9af633aa528f0
|
data/lib/assonnato.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
require 'uri'
|
12
|
+
require 'net/http'
|
13
|
+
require 'json'
|
14
|
+
|
15
|
+
require 'assonnato/exception'
|
16
|
+
require 'assonnato/request'
|
17
|
+
require 'assonnato/parser'
|
18
|
+
require 'assonnato/type/show'
|
19
|
+
require 'assonnato/type/episode'
|
20
|
+
require 'assonnato/assonnato'
|
21
|
+
require 'assonnato/version'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato; end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato
|
12
|
+
class ResourceNotFound < URI::Error; end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato
|
12
|
+
module Parser
|
13
|
+
|
14
|
+
def parse(what, format)
|
15
|
+
collection = case format.to_sym
|
16
|
+
when :json then JSON.parse what
|
17
|
+
when :xml, :csv, :yaml then raise NotImplementedError, 'the support for XML, CSV or YAML data is not supported yet'
|
18
|
+
else raise ArgumentError, 'format not recognized'
|
19
|
+
end
|
20
|
+
|
21
|
+
[].tap { |res|
|
22
|
+
[collection].flatten.each { |element|
|
23
|
+
keys = element.keys.map { |k| k.to_sym }
|
24
|
+
values = element.values
|
25
|
+
res << Struct.new(*keys).new(*values)
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato
|
12
|
+
module Request
|
13
|
+
def get(host, path)
|
14
|
+
uri = URI.join(host, '/api/', path[1..-1])
|
15
|
+
request :get, uri
|
16
|
+
end
|
17
|
+
|
18
|
+
def post(host, path, params = {})
|
19
|
+
uri = URI.join(host, '/api/', path[1..-1])
|
20
|
+
request :post, uri, params
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def request(method, url, params = {})
|
25
|
+
uri = URI url
|
26
|
+
ssl = uri.scheme == 'https'
|
27
|
+
|
28
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: ssl) do |http|
|
29
|
+
request = case method.to_sym
|
30
|
+
when :get
|
31
|
+
Net::HTTP::Get.new uri
|
32
|
+
when :post
|
33
|
+
Net::HTTP.post_form uri, params
|
34
|
+
else
|
35
|
+
raise ArgumentError, 'format not recognized'
|
36
|
+
end
|
37
|
+
response = http.request request
|
38
|
+
raise ResourceNotFound unless response.body
|
39
|
+
response.body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato
|
12
|
+
class Episode < Show
|
13
|
+
def all!(show)
|
14
|
+
parse get(@host, "/shows/get/#{URI.escape show}/episodes/list.#{@format}"), @format
|
15
|
+
end
|
16
|
+
|
17
|
+
def search!(keyword)
|
18
|
+
raise NotImplementedError, 'you can search only the shows'
|
19
|
+
end
|
20
|
+
|
21
|
+
def get!(show, episode)
|
22
|
+
parse get(@host, "/shows/get/#{URI.escape show}/episodes/get/#{episode}.#{@format}"), @format
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato
|
12
|
+
class Show
|
13
|
+
attr_accessor :host, :format
|
14
|
+
include Request
|
15
|
+
include Parser
|
16
|
+
|
17
|
+
def initialize(host, format = :json)
|
18
|
+
@host = host
|
19
|
+
@format = format
|
20
|
+
end
|
21
|
+
|
22
|
+
def all!
|
23
|
+
parse get(@host, "/shows/all.#{@format}"), @format
|
24
|
+
end
|
25
|
+
|
26
|
+
def search!(keyword)
|
27
|
+
parse get(@host, "/shows/search/#{URI.escape keyword}.#{@format}"), @format
|
28
|
+
end
|
29
|
+
|
30
|
+
def get!(show)
|
31
|
+
parse get(@host, "/shows/get/#{URI.escape show}.#{@format}"), @format
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module Assonnato
|
12
|
+
VERSION = '0.1'
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'assonnato'
|
3
|
+
|
4
|
+
describe 'Assonnato' do
|
5
|
+
before do
|
6
|
+
@episode = Assonnato::Episode.new 'http://localhost:4567', :json
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns all the episodes of the given show' do
|
10
|
+
res = @episode.all! 'Monogatari Second Series'
|
11
|
+
res.should be_kind_of(Array)
|
12
|
+
res.should_not be_empty
|
13
|
+
res.first.should be_kind_of(Struct)
|
14
|
+
res.first.id.should eql(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can\'t search episodes' do
|
18
|
+
expect {
|
19
|
+
@episode.search!('monogatari')
|
20
|
+
}.to raise_error(NotImplementedError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns a specific episode of the given show' do
|
24
|
+
res = @episode.get! 'Monogatari Second Series', 1
|
25
|
+
res.should be_kind_of(Array)
|
26
|
+
res.should_not be_empty
|
27
|
+
res.first.should be_kind_of(Struct)
|
28
|
+
res.first.episode.should eql(1)
|
29
|
+
end
|
30
|
+
end
|
data/spec/show_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'assonnato'
|
3
|
+
|
4
|
+
describe 'Assonnato' do
|
5
|
+
before do
|
6
|
+
@show = Assonnato::Show.new 'http://localhost:4567', :json
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns all the shows' do
|
10
|
+
res = @show.all!
|
11
|
+
res.should be_kind_of(Array)
|
12
|
+
res.should_not be_empty
|
13
|
+
res.first.should be_kind_of(Struct)
|
14
|
+
res.first.name.length.should > 5
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'search all the shows which name is similar to the given keyword' do
|
18
|
+
res = @show.search! 'monogatari'
|
19
|
+
res.should be_kind_of(Array)
|
20
|
+
res.should_not be_empty
|
21
|
+
res.first.should be_kind_of(Struct)
|
22
|
+
res.first.name.should eql('Monogatari Second Series')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'doesn\'t get an unknown show' do
|
26
|
+
res = @show.search! 'monogatarif'
|
27
|
+
res.should be_kind_of(Array)
|
28
|
+
res.should be_empty
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns all the informations of the given show' do
|
32
|
+
res = @show.get! 'Monogatari Second Series'
|
33
|
+
res.should be_kind_of(Array)
|
34
|
+
res.should_not be_empty
|
35
|
+
res.first.should be_kind_of(Struct)
|
36
|
+
res.first.id.should eql(1)
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assonnato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Capuano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: RESTful wrapper gem for pigro's APIs
|
56
|
+
email: webmaster@giovannicapuano.net
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/assonnato/assonnato.rb
|
62
|
+
- lib/assonnato/exception.rb
|
63
|
+
- lib/assonnato/parser.rb
|
64
|
+
- lib/assonnato/request.rb
|
65
|
+
- lib/assonnato/type/episode.rb
|
66
|
+
- lib/assonnato/type/show.rb
|
67
|
+
- lib/assonnato/version.rb
|
68
|
+
- lib/assonnato.rb
|
69
|
+
- spec/episode_spec.rb
|
70
|
+
- spec/show_spec.rb
|
71
|
+
homepage: http://www.giovannicapuano.net
|
72
|
+
licenses:
|
73
|
+
- WTFPL
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: RESTful gem wrapping pigro's APIs
|
95
|
+
test_files:
|
96
|
+
- spec/episode_spec.rb
|
97
|
+
- spec/show_spec.rb
|