ugigi 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
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ugigi.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Oame
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,34 @@
1
+ # Ugigi
2
+
3
+ Ugigi Wrapper for Ruby 1.9.x
4
+
5
+ ## Requirements
6
+
7
+ * Ruby 1.9.x
8
+ * mechanize gem
9
+
10
+ ## Installation
11
+
12
+ gem install ugigi
13
+
14
+ ## Usage
15
+
16
+ require "ugigi"
17
+
18
+ # フリーワード検索で"ナズーリン"が含まれているSSを持ってくる
19
+ naz_novels = Ugigi.search(:free => "ナズーリン")
20
+ puts naz_novels.size
21
+
22
+ # "寅丸星"がタグに設定されているSSを持ってくる
23
+ novels = Ugigi.search(:tag => "寅丸星")
24
+ novels.each do |novel|
25
+ puts novel.title
26
+ end
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/ugigi.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "kconv"
2
+ require "mechanize"
3
+ require "time"
4
+ require "json"
5
+ require "uri"
6
+
7
+ $LOAD_PATH.unshift(File.expand_path("../", __FILE__))
8
+ require "ugigi/version"
9
+ require "ugigi/scheme"
10
+ require "ugigi/parser"
11
+
12
+ module Ugigi
13
+ BASE_URL = "http://ugigi.dvrdns.org/api/search/list.json"
14
+
15
+ # @param [Hash] parameter
16
+ # @return [String] URL Serialized parameters
17
+ def self.serialize_parameter parameter
18
+ return "" unless parameter.class == Hash
19
+ ant = Hash.new
20
+ parameter.each do |key, value|
21
+ ant[key.to_sym] = value.to_s
22
+ end
23
+ param = ant.inject(""){|k,v|k+"&#{v[0]}=#{URI.escape(v[1])}"}.sub!(/^&/,"?")
24
+ return param ? param : ""
25
+ end
26
+
27
+ def self.search(args={})
28
+ parser = Parser.new
29
+ parser.fetch(args)
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module Ugigi
2
+ class Parser
3
+ def initialize
4
+ @agent = Mechanize.new
5
+ @agent.user_agent = "Ugigi Ruby #{Ugigi::VERSION}"
6
+ end
7
+
8
+ def fetch(args)
9
+ params = Ugigi.serialize_parameter(args)
10
+ page = @agent.get(URI.join(BASE_URL, params))
11
+ data = JSON.parse(page.body)
12
+ indexes = []
13
+ data.each do |e|
14
+ index = Index.new(e)
15
+ indexes << index
16
+ end
17
+ return indexes
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Ugigi
2
+ class Scheme
3
+ protected
4
+
5
+ def method_missing(action, *args)
6
+ return @element[action.to_s] rescue nil
7
+ end
8
+
9
+ public
10
+
11
+ def params() @element.keys.map{|k|k.to_sym} ; end
12
+ alias_method :available_methods, :params
13
+ end
14
+
15
+ class Index < Scheme
16
+ def initialize(element)
17
+ @element = element
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Ugigi
2
+ VERSION = "0.0.1"
3
+ end
data/ugigi.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ugigi/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Oame"]
6
+ gem.email = ["oame@oameya.com"]
7
+ gem.description = %q{Ugigi Wrapper for Ruby}
8
+ gem.summary = %q{Ugigi Wrapper for Ruby 1.9.x}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ugigi"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Ugigi::VERSION
17
+ gem.add_dependency "mechanize"
18
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ugigi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Oame
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &70314480816760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70314480816760
25
+ description: Ugigi Wrapper for Ruby
26
+ email:
27
+ - oame@oameya.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/ugigi.rb
38
+ - lib/ugigi/parser.rb
39
+ - lib/ugigi/scheme.rb
40
+ - lib/ugigi/version.rb
41
+ - ugigi.gemspec
42
+ homepage: ''
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.10
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ugigi Wrapper for Ruby 1.9.x
66
+ test_files: []
67
+ has_rdoc: