greentext 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rubocop.yml +7 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +8 -0
- data/greentext.gemspec +27 -0
- data/lib/greentext.rb +0 -0
- data/lib/greentext/client.rb +0 -0
- data/lib/greentext/dirty.rb +50 -0
- data/spec/spec_helper.rb +24 -0
- metadata +170 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 219465b29edc32e5ba85d822d9b08f353a559808
|
4
|
+
data.tar.gz: 48a6b15ddea763362e67106088040dceaa4d5f95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21abfe740a2cc63e9236cacf0a69abaab5dde707f88f802c3015bffaa2f953bc3a52ec3ce2d7296727f4d9b7c47ab546cd0f77dfbb3e703f9ec2166efbba4969
|
7
|
+
data.tar.gz: 3c3899bc4bd78d75801f81d2bdcd0b028316efe259293d41eacb99f43ec086682056a25d19a951df78d5bb174b6e0c079bf1a8ed3511c232bbf67d3eea50eec9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Avinash Dwarapu
|
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,58 @@
|
|
1
|
+
**Greentext** *Unofficial 4chan API.*
|
2
|
+
By Avinash Dwarapu
|
3
|
+
|
4
|
+
**
|
5
|
+
[Usage](#usage) |
|
6
|
+
[Installation](#installation) |
|
7
|
+
[Contributing](#contributing)
|
8
|
+
**
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
### Greentext::Client
|
12
|
+
Haven't implemented it yet :neutral_face:
|
13
|
+
|
14
|
+
### Greentext::Dirty
|
15
|
+
Aside from the main implementation, there is also a quick
|
16
|
+
way of getting data from the API using `Greentext::Dirty`.
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require "greentext/dirty"
|
20
|
+
dirty = Greentext::Dirty.new
|
21
|
+
|
22
|
+
boards = dirty.boards
|
23
|
+
# => [{"board"=>"3", "title"=>"3DCG" ... }, {"board"=>"a" ...
|
24
|
+
|
25
|
+
board = dirty.board(:v)
|
26
|
+
# => [{:no=>543128225, :last_modified=>1398021394}, {:no=> ...
|
27
|
+
|
28
|
+
thread = dirty.thread(:v, 543125139)
|
29
|
+
# => [{:no=>543125139, :now=>"04/20/14(Sun)14:28:49", ...
|
30
|
+
|
31
|
+
thread.first[:time]
|
32
|
+
# => #<DateTime: 2014-04-20T18:28:49+00:00 ((2456768j,66529s,0n),+0s,2299161j)>
|
33
|
+
|
34
|
+
thread.first[:url]
|
35
|
+
# => "http://boards.4chan.org/b/res/543125139#p543128395"
|
36
|
+
```
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
Add this line to your application's Gemfile:
|
41
|
+
|
42
|
+
gem 'greentext'
|
43
|
+
|
44
|
+
And then execute:
|
45
|
+
|
46
|
+
$ bundle
|
47
|
+
|
48
|
+
Or install it yourself as:
|
49
|
+
|
50
|
+
$ gem install greentext
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it ( http://github.com/avidw/greentext/fork )
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/greentext.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "greentext"
|
5
|
+
s.version = "0.1.0"
|
6
|
+
s.authors = ["Avinash Dwarapu"]
|
7
|
+
s.email = ["d.nash.avi@gmail.com"]
|
8
|
+
s.summary = %q{Unofficial API for 4chan.}
|
9
|
+
s.description = %q{Unofficial API for 4chan.}
|
10
|
+
s.homepage = "https://github.com/avidw/greentext"
|
11
|
+
s.license = "MIT"
|
12
|
+
|
13
|
+
s.files = `git ls-files -z`.split("\x0")
|
14
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency "faraday", "~> 0.9"
|
19
|
+
s.add_dependency "memoizable", "~> 0.4.2"
|
20
|
+
s.add_dependency "oj"
|
21
|
+
|
22
|
+
s.add_development_dependency "rubocop"
|
23
|
+
s.add_development_dependency "rspec"
|
24
|
+
s.add_development_dependency "webmock"
|
25
|
+
s.add_development_dependency "vcr"
|
26
|
+
s.add_development_dependency "rake"
|
27
|
+
end
|
data/lib/greentext.rb
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "cgi"
|
3
|
+
require "oj"
|
4
|
+
|
5
|
+
module Greentext
|
6
|
+
# Public: Crudely written but quick way to access the 4chan API.
|
7
|
+
# Surprisingly, Rubocop's pretty okay with this mess.
|
8
|
+
#
|
9
|
+
# Examples
|
10
|
+
#
|
11
|
+
# Greentext.new.threads(:b)
|
12
|
+
# # => [{"no" => 543103136, "last_modified" => 1398012243}, ...
|
13
|
+
class Dirty
|
14
|
+
def boards
|
15
|
+
get("/boards.json")["boards"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def threads(board)
|
19
|
+
get("/#{board}/threads.json")
|
20
|
+
.map { |page| page["threads"] }.flatten
|
21
|
+
.map { |post| Hash[post.map { |k, v| [k.to_sym, v] }] }
|
22
|
+
end
|
23
|
+
alias_method :board, :threads
|
24
|
+
|
25
|
+
def posts(board, thread)
|
26
|
+
get("/#{board}/res/#{thread}.json")["posts"]
|
27
|
+
.sort_by { |h| h["resto"] }
|
28
|
+
.map do |post|
|
29
|
+
post.merge!("time" => DateTime.strptime(post["time"].to_s, "%s"))
|
30
|
+
post.merge!("name" => nil) if post["name"] == "Anonymous"
|
31
|
+
post["url"] =
|
32
|
+
"http://boards.4chan.org/#{board}/res/" \
|
33
|
+
"#{post['resto'] == 0 ? post['no'] : post['resto']}#p#{post['no']}"
|
34
|
+
Hash[post.map { |k, v| [k.to_sym, v] }]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
alias_method :thread, :posts
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def get(path)
|
42
|
+
res = Faraday.new(url: "http://a.4cdn.org/").get(path)
|
43
|
+
if res.headers["Content-Type"] == "application/json"
|
44
|
+
Oj.load(res.body)
|
45
|
+
else
|
46
|
+
res
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "greentext"
|
2
|
+
require "webmock/rspec"
|
3
|
+
require "vcr"
|
4
|
+
|
5
|
+
VCR.configure do |c|
|
6
|
+
c.cassette_library_dir = "spec/cassettes"
|
7
|
+
c.hook_into :webmock
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |c|
|
11
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
c.run_all_when_everything_filtered = true
|
13
|
+
c.filter_run :focus
|
14
|
+
c.order = "random"
|
15
|
+
|
16
|
+
c.around(:each, :vcr) do |example|
|
17
|
+
name = example.metadata[:full_description]
|
18
|
+
.split(/\s+/, 2)
|
19
|
+
.join("/")
|
20
|
+
.underscore
|
21
|
+
.gsub(/[^\w\/]+/, "_")
|
22
|
+
VCR.use_cassette(name) { example.call }
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: greentext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Avinash Dwarapu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: memoizable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oj
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vcr
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Unofficial API for 4chan.
|
126
|
+
email:
|
127
|
+
- d.nash.avi@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- greentext.gemspec
|
141
|
+
- lib/greentext.rb
|
142
|
+
- lib/greentext/client.rb
|
143
|
+
- lib/greentext/dirty.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: https://github.com/avidw/greentext
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.0.14
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Unofficial API for 4chan.
|
169
|
+
test_files:
|
170
|
+
- spec/spec_helper.rb
|