rubyhexagon 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/bin/e621 CHANGED
@@ -18,6 +18,8 @@
18
18
  along with rubyhexahon. If not, see <http://www.gnu.org/licenses/>.
19
19
  =end
20
20
 
21
- require "rubyhexahon"
21
+ $:.unshift File.dirname(__FILE__)+"/../lib"
22
+
23
+ require "rubyhexagon"
22
24
 
23
25
  require "examples/#{ARGV.shift}"
data/lib/container.rb CHANGED
@@ -35,6 +35,8 @@ module E621
35
35
  v = Time.at(v)
36
36
  elsif k == "cached_tags" then
37
37
  k = "tags"
38
+ elsif k == "posts" then
39
+ v.map!{|post|Post.new(post)}
38
40
  end
39
41
  instance_variable_set("@#{k}",v)
40
42
  end
data/lib/examples/add.rb CHANGED
@@ -28,7 +28,7 @@ $0 = "E621 #{mod}"
28
28
  E621::Config.config = File.expand_path("~/.hexagon/conf.json")
29
29
  Dir.chdir(File.expand_path(E621::Config.paths["home"])) do
30
30
  pools, api = Array.new, API.new(mod)
31
- File.open(E621::Config.paths["j#{mod}s"]) do |f|
31
+ File.open(File.expand_path(E621::Config.paths["j#{mod}s"])) do |f|
32
32
  pools = JSON.parser.new(f.read).parse
33
33
  end
34
34
  puts "Old count: #{pools.length}"
@@ -40,7 +40,7 @@ Dir.chdir(File.expand_path(E621::Config.paths["home"])) do
40
40
  if pool["id"] && mod == "pool" then
41
41
  pools << id
42
42
  elsif pool["id"] && mod == "set" then
43
- pools << {"id"=>pool["id"],"owner"=>pool["user-id"]}
43
+ pools << {"id"=>pool["id"],"owner"=>pool["user_id"]}
44
44
  end
45
45
  end
46
46
  puts "Adding: #{new.length}"
@@ -51,7 +51,7 @@ Dir.chdir(File.expand_path(E621::Config.paths["home"])) do
51
51
  end
52
52
  puts "New count: #{pools.length}"
53
53
  pools = pools.to_json
54
- File.open(E621::Config.paths["j#{mod}s"]) do |f|
54
+ File.open(File.expand_path(E621::Config.paths["j#{mod}s"]),"w") do |f|
55
55
  f.print pools
56
56
  end
57
57
  end
data/lib/pool.rb CHANGED
@@ -22,6 +22,7 @@ require "digest/md5"
22
22
  module E621
23
23
  class Pool < Container
24
24
  def initialize(post)
25
+ @api = API.new("pool")
25
26
  set_variables(post)
26
27
  end
27
28
 
@@ -50,5 +51,15 @@ module E621
50
51
  end
51
52
  return json_hash.to_json
52
53
  end
54
+
55
+ def each_post
56
+ (@post_count/24.0).ceil.times do |page|
57
+ @posts.each do |post|
58
+ yield post
59
+ end
60
+ post = api.get("show",{"id"=>@id,"page"=>page+2})
61
+ set_variables(post)
62
+ end
63
+ end
53
64
  end
54
65
  end
data/lib/post.rb CHANGED
@@ -36,7 +36,12 @@ module E621
36
36
  end
37
37
 
38
38
  def download(where)
39
- host,port = @file_url.sub(%r{^.+?//},"").sub(%r{/.+$},""),@file_url.match(/^https/) ? 443 : 80
39
+ if @file_url then
40
+ host,port = @file_url.sub(%r{^.+?//},"").sub(%r{/.+$},""),@file_url.match(/^https/) ? 443 : 80
41
+ else
42
+ host,port = "static1.e621.net",443
43
+ @file_url = "/data/#{@md5[0,2]}/#{@md5[2,2]}/#@md5.#@file_ext"
44
+ end
40
45
  http = HTTP.new(host,port)
41
46
  if !File.exist?(where) then
42
47
  body = ""
data/lib/rubyhexagon.rb CHANGED
@@ -30,5 +30,5 @@ require "pool"
30
30
 
31
31
  module E621
32
32
  Name = "rubyhexagon"
33
- Version = "0.1.0"
33
+ Version = "0.1.1"
34
34
  end
data/lib/set.rb CHANGED
@@ -20,17 +20,27 @@
20
20
  module E621
21
21
  class Set < Container
22
22
  def initialize(post)
23
- set_variables(post)
23
+ @api,@page = API.new("set"),1
24
+ if post.is_a?(Hash) then
25
+ set_variables(post)
26
+ elsif post.is_a?(Fixnum) then
27
+ set_variables(@api.get("show",{"id"=>post}))
28
+ else
29
+ raise ArgumentError, "Parameter must be Hash or Number."
30
+ end
24
31
  end
25
32
 
26
33
  def add_post(id)
27
- api = API.new("set")
28
- api.post("add_post",{"post_id"=>id,"set_id"=>@id})
34
+ @api.post("add_post",{"post_id"=>id,"set_id"=>@id})
29
35
  end
30
36
 
31
37
  def keys
32
38
  return instance_variables.map{|i|i.to_s.sub("@","")}
33
39
  end
40
+
41
+ def name=(name)
42
+ @name = name
43
+ end
34
44
 
35
45
  def to_json
36
46
  json_hash = Hash.new
@@ -39,5 +49,11 @@ module E621
39
49
  end
40
50
  return json_hash.to_json
41
51
  end
52
+
53
+ def each_post
54
+ @posts.each do |post|
55
+ yield post
56
+ end
57
+ end
42
58
  end
43
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyhexagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -18,21 +18,21 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - lib/pool.rb
22
- - lib/examples/add.rb
23
- - lib/rubyhexagon.rb
24
- - lib/standard/hash.rb
25
- - lib/standard/http.rb
21
+ - lib/config.rb
22
+ - lib/set.rb
26
23
  - lib/standard/error.rb
24
+ - lib/standard/http.rb
27
25
  - lib/standard/string.rb
28
26
  - lib/standard/time.rb
29
27
  - lib/standard/int.rb
30
- - lib/post.rb
28
+ - lib/standard/hash.rb
29
+ - lib/api.rb
30
+ - lib/rubyhexagon.rb
31
+ - lib/pool.rb
31
32
  - lib/search.rb
32
33
  - lib/container.rb
33
- - lib/config.rb
34
- - lib/api.rb
35
- - lib/set.rb
34
+ - lib/post.rb
35
+ - lib/examples/add.rb
36
36
  - bin/e621
37
37
  homepage: https://github.com/maxine-red/rubyhexagon
38
38
  licenses: