api_2ch 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3294b6790a1163ad4e693cc0e1d69a600cd7309e
4
+ data.tar.gz: 81a29a083d7d039e24b3b21a0d9ceb300e4e00d5
5
+ SHA512:
6
+ metadata.gz: 8fc1e9a22adf6379adcc411352881723175481d59cd9f1dd8416fb2fd8dec5752eee8094f11ad54b11d43f9b6249ec60da203d3b675cfb83c3c0b42ace3677bd
7
+ data.tar.gz: 108fd936d058aedc0bf6355c507ab7e9a61f17e27a5cc0195f42c2f960a887e9539b01995ab0f6be5548d7dd05ebb9ce154748ceb293f41df638a4d9c0c69444
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in api_2ch.gemspec
4
+ gemspec
@@ -0,0 +1,98 @@
1
+ # Api2ch
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'api_2ch'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install api_2ch
18
+
19
+ ## Usage
20
+ Create new Request
21
+ ```ruby
22
+ request = Api2ch::Request.new
23
+ ```
24
+ Then, get json with thread list.
25
+ ```ruby
26
+ @threads = request.call_threads('pr')
27
+ ```
28
+ For example, lets put in view name of threads
29
+ ```slim
30
+ - @threads["threads"].each do |thread|
31
+ p= thread["subject"]
32
+ small= "Views: #{thread['views']}"
33
+ hr
34
+ ```
35
+
36
+ ## Api
37
+
38
+ #### Get threads json.
39
+ ```ruby
40
+ @threads = request.call_threads('pr')
41
+ ```
42
+
43
+ #### Get threads json with full info.
44
+ ```ruby
45
+ @threads = request.call_full_threads('pr', page) #default: 'index'
46
+ ```
47
+
48
+ #### Get most viewed threads.
49
+ ```ruby
50
+ @threads = request.call_most_viewed_threads('fg')
51
+ ```
52
+
53
+ #### Get posts from thread.
54
+ ```ruby
55
+ @threads = request.call_thread_posts('rf', 543235) #second argument - thread number
56
+ ```
57
+
58
+ #### Get latest bumped threads.
59
+ ```ruby
60
+ @threads = request.call_latest_bump_threads('ga')
61
+ ```
62
+
63
+ #### Get recent created threads.
64
+ ```ruby
65
+ @threads = request.call_new_threads('sci')
66
+ ```
67
+
68
+ ```json
69
+ ["timestamp"] = The creation of the thread
70
+ ["threads"] = Array of threads
71
+ ["subject"] = Thread name
72
+ ["views"] = Thread views
73
+ ["board"] = Board name
74
+ ["score"] = Popularity thread
75
+ ["num"] = Thread number
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it ( https://github.com/ID25/api_2ch/fork )
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create a new Pull Request
85
+
86
+ ## The MIT License (MIT)
87
+
88
+ Copyright (c) 2015 ID25
89
+
90
+ Permission is hereby granted, free of charge, to any person obtaining a copy
91
+ of this software and associated documentation files (the "Software"), to deal
92
+ in the Software without restriction, including without limitation the rights
93
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
94
+ copies of the Software, and to permit persons to whom the Software is
95
+ furnished to do so, subject to the following conditions:
96
+
97
+ The above copyright notice and this permission notice shall be included in
98
+ all copies or substantial portions of the Software.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'api_2ch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "api_2ch"
8
+ spec.version = Api2ch::VERSION
9
+ spec.authors = ["ID25"]
10
+ spec.email = ["xid25x@gmail.com"]
11
+
12
+ spec.summary = "Simple 2ch.hk API"
13
+ spec.homepage = "https://github.com/ID25/api_2ch"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "httparty"
24
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "api_2ch"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require 'httparty'
2
+ require 'api_2ch/version'
3
+ require 'api_2ch/methods/threads'
4
+ require 'api_2ch/methods/posts'
5
+ require 'api_2ch/methods/latest_threads'
6
+ require 'api_2ch/methods/viewed_threads'
7
+ require 'api_2ch/methods/new_threads'
8
+ require 'api_2ch/request'
9
+
10
+ module Api2ch
11
+ BASE_URL = 'https://2ch.hk/'
12
+ end
@@ -0,0 +1,19 @@
1
+ module Api2ch
2
+ class LatestThreads
3
+ def initialize(board)
4
+ @board = board
5
+ end
6
+
7
+ def call
8
+ response = HTTParty.get("#{BASE_URL}#{@board}/catalog.json")
9
+ json = JSON.parse(response.body)
10
+ @subjects = []
11
+ @comments = []
12
+ json['threads'].each do |thread|
13
+ @subjects << thread['subject']
14
+ @comments << thread['comment']
15
+ end
16
+ Hash[@subjects.zip(@comments)]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Api2ch
2
+ class NewThreads
3
+ def initialize(board)
4
+ @board = board
5
+ end
6
+
7
+ def call
8
+ response = HTTParty.get("#{BASE_URL}#{@board}/catalog_num.json")
9
+ json = JSON.parse(response.body)
10
+ json['threads']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Api2ch
2
+ class Posts
3
+ def initialize(board, num)
4
+ @board = board
5
+ @num = num
6
+ end
7
+
8
+ def call
9
+ response = HTTParty.get("#{BASE_URL}#{@board}/res/#{@num}.json")
10
+ json = JSON.parse(response.body)
11
+ json['threads'].each do |thread|
12
+ return thread['posts'].map { |post| post }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module Api2ch
2
+ class Threads
3
+ def initialize(board, page)
4
+ @board = board
5
+ @page = page
6
+ end
7
+
8
+ def full
9
+ response = HTTParty.get("#{BASE_URL}#{@board}/#{@page}.json")
10
+ JSON.parse(response.body)
11
+ end
12
+
13
+ def call
14
+ response = HTTParty.get("#{BASE_URL}#{@board}/threads.json")
15
+ JSON.parse(response.body)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module Api2ch
2
+ class ViewedThreads
3
+ def initialize(board)
4
+ @board = board
5
+ end
6
+
7
+ def call
8
+ board_threads = make_request(@board)
9
+ board_threads['threads'].map { |i| i['subject'].scrub! }
10
+ board_threads['threads'].sort_by { |i| - i['views'] }
11
+ end
12
+
13
+ private
14
+
15
+ def make_request(board)
16
+ response = HTTParty.get("#{BASE_URL}#{@board}/threads.json")
17
+ JSON.parse(response.body)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module Api2ch
2
+ class Request
3
+ def initialize(board = 'b')
4
+ @board = board
5
+ end
6
+
7
+ def call_full_threads(board, page = 'index')
8
+ Api2ch::Threads.new(board, page).full
9
+ end
10
+
11
+ def call_threads(board)
12
+ Api2ch::Threads.new(board, nil).call
13
+ end
14
+
15
+ def call_thread_posts(board, num)
16
+ Api2ch::Posts.new(board, num).call
17
+ end
18
+
19
+ def call_latest_bump_threads(board)
20
+ Api2ch::LatestThreads.new(board).call
21
+ end
22
+
23
+ def call_most_viewed_threads(board)
24
+ Api2ch::ViewedThreads.new(board).call
25
+ end
26
+
27
+ def call_new_threads(board)
28
+ Api2ch::NewThreads.new(board).call
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Api2ch
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_2ch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - ID25
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
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
+ description:
56
+ email:
57
+ - xid25x@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - api_2ch.gemspec
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/api_2ch.rb
71
+ - lib/api_2ch/methods/latest_threads.rb
72
+ - lib/api_2ch/methods/new_threads.rb
73
+ - lib/api_2ch/methods/posts.rb
74
+ - lib/api_2ch/methods/threads.rb
75
+ - lib/api_2ch/methods/viewed_threads.rb
76
+ - lib/api_2ch/request.rb
77
+ - lib/api_2ch/version.rb
78
+ homepage: https://github.com/ID25/api_2ch
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Simple 2ch.hk API
102
+ test_files: []