greentext 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -48
- data/greentext.gemspec +2 -2
- data/lib/greentext.rb +5 -2
- data/lib/greentext/board.rb +1 -1
- data/lib/greentext/client/board.rb +3 -2
- data/lib/greentext/client/post.rb +1 -1
- data/lib/greentext/post.rb +20 -9
- data/spec/board_spec.rb +3 -2
- data/spec/post_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- metadata +3 -4
- data/lib/greentext/dirty.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea6f17edaac64598a494d1a439d5db64b98230f
|
4
|
+
data.tar.gz: 06f28533e8e7cc84713f1d581778ce27989e9569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4c9edbd694256e8990774ca31b93bf6ac62d65058fcfbd004c3542a2cfaed812278de462b111ec26b02888a665ee4cfaee2cc728562587a5a0bacd52c16ea2
|
7
|
+
data.tar.gz: 9ef8f01dccf3d3d01f4734c56ec42290f16c4dd85bf18b24b7a096dcde9ec0954e937f8a122e149a8c4fc2d641655fee80de9b4a5f8556eca5090880b2aff2b9
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
**Greentext**
|
1
|
+
**Greentext**
|
2
|
+
*Unofficial [4chan's JSON API](https://github.com/4chan/4chan-API) Wrapper for Ruby.*
|
2
3
|
|
3
4
|
[![Gem Version](https://badge.fury.io/rb/greentext.svg)](http://badge.fury.io/rb/greentext)
|
4
5
|
[![Dependency Status](https://gemnasium.com/avidw/greentext.svg)](https://gemnasium.com/avidw/greentext)
|
@@ -6,71 +7,46 @@
|
|
6
7
|
|
7
8
|
---
|
8
9
|
|
9
|
-
##
|
10
|
-
### Greentext::Dirty
|
11
|
-
|
12
|
-
I'm still working on the main implementation. Meanwhile, one
|
13
|
-
way of getting data from the API is using `Greentext::Dirty`.
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
require "greentext/dirty"
|
17
|
-
dirty = Greentext::Dirty.new
|
10
|
+
## Installation
|
18
11
|
|
19
|
-
|
20
|
-
# => [{"board"=>"3", "title"=>"3DCG" ... }, {"board"=>"a" ...
|
12
|
+
Add this line to your application's Gemfile:
|
21
13
|
|
22
|
-
|
23
|
-
# => [{:no=>543128225, :last_modified=>1398021394}, {:no=> ...
|
14
|
+
gem "greentext"
|
24
15
|
|
25
|
-
|
26
|
-
# => [{:no=>543125139, :now=>"04/20/14(Sun)14:28:49", ...
|
16
|
+
And then execute:
|
27
17
|
|
28
|
-
|
29
|
-
# => #<DateTime: 2014-04-20T18:28:49+00:00 ((2456768j,66529s,0n),+0s,2299161j)>
|
18
|
+
$ bundle
|
30
19
|
|
31
|
-
|
32
|
-
# => "http://boards.4chan.org/b/res/543125139#p543128395"
|
33
|
-
```
|
20
|
+
Or install it yourself as:
|
34
21
|
|
35
|
-
|
22
|
+
$ gem install greentext
|
36
23
|
|
37
|
-
|
38
|
-
Meanwhile, use `Greentext::Dirty`.
|
24
|
+
## Usage
|
39
25
|
|
40
26
|
```ruby
|
41
27
|
require "greentext"
|
42
28
|
|
43
|
-
client = Greentext
|
44
|
-
# => #<Greentext::Client:0x007f9f9a624260 @
|
29
|
+
client = Greentext.client
|
30
|
+
# => #<Greentext::Client:0x007f9f9a624260 @api_endpoint="http://a.4cdn.org/">
|
45
31
|
|
46
|
-
|
47
|
-
# => #<Greentext::
|
48
|
-
|
32
|
+
board = client.boards.first
|
33
|
+
# => #<Greentext::Board:0x007f9f9aa10928 @attrs={"board"=>"3", "title"=>"3DCG", "ws_board"=>1, ... }>
|
34
|
+
board.title
|
49
35
|
# => "3DCG"
|
50
|
-
|
36
|
+
board.worksafe?
|
51
37
|
# => true
|
52
38
|
|
53
|
-
|
54
|
-
# => #<Greentext::
|
55
|
-
|
39
|
+
thread = board.threads.first
|
40
|
+
# => #<Greentext::Post:0x005f4f9aa12393 @attrs={"no"=>240555661, "now"=>"04\/21\/14(Mon)13:26:27", ... }>
|
41
|
+
thread.time
|
56
42
|
# => #<DateTime: 2014-04-21T18:24:10+00:00 ((2456769j,66250s,699039399n),+0s,2299161j)>
|
57
|
-
|
43
|
+
thread.comment
|
58
44
|
# => "Love it. Looks like there's going to be ton of secret ... "
|
59
|
-
```
|
60
45
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
gem "greentext"
|
66
|
-
|
67
|
-
And then execute:
|
68
|
-
|
69
|
-
$ bundle
|
70
|
-
|
71
|
-
Or install it yourself as:
|
72
|
-
|
73
|
-
$ gem install greentext
|
46
|
+
# Get the rest of the thread from OP's post
|
47
|
+
all_posts = thread.expand
|
48
|
+
# => [#<Greentext::Post:0x005f4f9aa26345>, #<Greentext::Post:0x005f4f9aa27456>
|
49
|
+
```
|
74
50
|
|
75
51
|
## Contributing
|
76
52
|
|
data/greentext.gemspec
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "greentext"
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.1"
|
6
6
|
s.authors = ["Avinash Dwarapu"]
|
7
7
|
s.email = ["d.nash.avi@gmail.com"]
|
8
8
|
s.summary = %q{Unofficial API for 4chan.}
|
9
9
|
s.description = %q{Unofficial API for 4chan.}
|
10
|
-
s.homepage = "https://github.
|
10
|
+
s.homepage = "https://avidw.github.io/greentext"
|
11
11
|
s.license = "MIT"
|
12
12
|
|
13
13
|
s.files = `git ls-files -z`.split("\x0")
|
data/lib/greentext.rb
CHANGED
@@ -18,8 +18,11 @@ module Greentext
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def method_missing(method_name, *args, &block)
|
21
|
-
|
22
|
-
|
21
|
+
if client.respond_to?(method_name)
|
22
|
+
client.send(method_name, *args, &block)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
data/lib/greentext/board.rb
CHANGED
@@ -14,11 +14,12 @@ module Greentext
|
|
14
14
|
|
15
15
|
# Public: List all available threads in a board.
|
16
16
|
#
|
17
|
-
# board - A Greentext::Board object.
|
17
|
+
# board - A Greentext::Board object or a board name String/Symbol.
|
18
18
|
#
|
19
19
|
# Returns an Array of Greentext::Post instances.
|
20
20
|
def threads(board)
|
21
|
-
|
21
|
+
name = board.is_a?(Greentext::Board) ? board.name : board
|
22
|
+
get("/#{name}/catalog.json")
|
22
23
|
.map { |page| page["threads"] }.flatten
|
23
24
|
.map { |thread| Greentext::Post.new(thread.merge("board" => board)) }
|
24
25
|
end
|
data/lib/greentext/post.rb
CHANGED
@@ -39,21 +39,32 @@ module Greentext
|
|
39
39
|
#
|
40
40
|
# Returns a Hash.
|
41
41
|
def image
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
if @attrs["tim"]
|
43
|
+
{
|
44
|
+
width: @attrs["w"],
|
45
|
+
height: @attrs["h"],
|
46
|
+
filename: @attrs["tim"],
|
47
|
+
md5: @attrs["md5"],
|
48
|
+
url: "https://i.4cdn.org/#{@attrs['board'].name}/" \
|
49
|
+
"#{@attrs['tim']}#{@attrs['ext']}"
|
50
|
+
}
|
51
|
+
else
|
52
|
+
{}
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
# Public: Get information about the thumbnail of the image.
|
52
57
|
#
|
53
58
|
# Returns a Hash.
|
54
59
|
def thumbnail
|
55
|
-
|
56
|
-
|
60
|
+
if @attrs["tim"]
|
61
|
+
{ width: @attrs["tn_w"], height: @attrs["tn_h"],
|
62
|
+
url: "https://t.4cdn.org/#{@attrs['board'].name}/" \
|
63
|
+
"#{@attrs['tim']}s.jpg"
|
64
|
+
}
|
65
|
+
else
|
66
|
+
{}
|
67
|
+
end
|
57
68
|
end
|
58
69
|
|
59
70
|
# Public: Determines if the post is OP.
|
data/spec/board_spec.rb
CHANGED
@@ -10,14 +10,15 @@ describe Greentext::Board, :vcr do
|
|
10
10
|
expect(@client.boards.sample).to be_an_instance_of(Greentext::Board)
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
describe "#threads" do
|
15
15
|
it "gets an Array of posts" do
|
16
16
|
expect(@client.threads(@client.boards.sample)).to be_an(Array)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "converts objects to Greentext::Post instances" do
|
20
|
-
expect(@client.threads(@client.boards.sample).sample)
|
20
|
+
expect(@client.threads(@client.boards.sample).sample)
|
21
|
+
.to be_an_instance_of(Greentext::Post)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/spec/post_spec.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "spec_helper"
|
1
|
+
require "spec_helper"
|
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require "webmock/rspec"
|
|
3
3
|
require "vcr"
|
4
4
|
|
5
5
|
VCR.configure do |c|
|
6
|
-
c.default_cassette_options = {record: :new_episodes}
|
6
|
+
c.default_cassette_options = { record: :new_episodes }
|
7
7
|
c.cassette_library_dir = "spec/cassettes"
|
8
8
|
c.hook_into :webmock
|
9
9
|
end
|
@@ -17,13 +17,13 @@ RSpec.configure do |c|
|
|
17
17
|
c.before :all do
|
18
18
|
@client = Greentext.client
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
c.around(:each, :vcr) do |example|
|
22
22
|
name = example.metadata[:full_description]
|
23
23
|
.split(/\s+/, 2)
|
24
24
|
.join("/")
|
25
25
|
.downcase
|
26
|
-
.tr(
|
26
|
+
.tr(" ", "_")
|
27
27
|
.gsub(/[^\w\/]+/, "_")
|
28
28
|
VCR.use_cassette(name) { example.call }
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greentext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Avinash Dwarapu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -158,13 +158,12 @@ files:
|
|
158
158
|
- lib/greentext/client.rb
|
159
159
|
- lib/greentext/client/board.rb
|
160
160
|
- lib/greentext/client/post.rb
|
161
|
-
- lib/greentext/dirty.rb
|
162
161
|
- lib/greentext/post.rb
|
163
162
|
- spec/board_spec.rb
|
164
163
|
- spec/client_spec.rb
|
165
164
|
- spec/post_spec.rb
|
166
165
|
- spec/spec_helper.rb
|
167
|
-
homepage: https://github.
|
166
|
+
homepage: https://avidw.github.io/greentext
|
168
167
|
licenses:
|
169
168
|
- MIT
|
170
169
|
metadata: {}
|
data/lib/greentext/dirty.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require "faraday"
|
2
|
-
require "json"
|
3
|
-
|
4
|
-
module Greentext
|
5
|
-
# Public: Crudely written but quick way to access the 4chan API.
|
6
|
-
# Surprisingly, Rubocop's pretty okay with this mess.
|
7
|
-
class Dirty
|
8
|
-
def boards
|
9
|
-
get("/boards.json")["boards"]
|
10
|
-
end
|
11
|
-
|
12
|
-
def threads(board)
|
13
|
-
get("/#{board}/threads.json")
|
14
|
-
.map { |page| page["threads"] }.flatten
|
15
|
-
.map { |thread| symbolize(thread) }
|
16
|
-
end
|
17
|
-
alias_method :board, :threads
|
18
|
-
|
19
|
-
def posts(board, thread)
|
20
|
-
get("/#{board}/res/#{thread}.json")["posts"]
|
21
|
-
.map { |post| symbolize(post) }
|
22
|
-
end
|
23
|
-
alias_method :thread, :posts
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def get(path)
|
28
|
-
res = Faraday.new(url: "http://a.4cdn.org/").get(path).body
|
29
|
-
JSON.parse(res) if res.length > 2
|
30
|
-
end
|
31
|
-
|
32
|
-
def symbolize(hash)
|
33
|
-
Hash[hash.map { |k, v| [k.to_sym, v] }]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|