rumors-api-client 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +5 -3
- data/bin/console +2 -2
- data/lib/rumors/api/client/base.rb +10 -5
- data/lib/rumors/api/client/utils/list_articles.rb +24 -12
- data/lib/rumors/api/client/version.rb +1 -1
- data/lib/rumors/api/client.rb +0 -1
- metadata +3 -7
- data/Gemfile.lock +0 -67
- data/lib/rumors/api/client/utils/get_article_and_replies.rb +0 -38
- data/rumors-api-client-0.1.1.gem +0 -0
- data/rumors-api-client-0.1.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e01c7b9c0baec0166aa6dbd36e44d1c9598a7dac1c51bc34eb8c3128d06bae65
|
4
|
+
data.tar.gz: 6fa1296b339fcb393c978796e15fdcbf6e4e115ba012fa3b05a2324b37bc752b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '090d5f3963c7e08b457678a3d5e14d8af9d6e232794bbf83838d72530bf6d317f8cad9cb0752a302ed3d1e2972db65925505723a1e86655af134f036b709e6a2'
|
7
|
+
data.tar.gz: 5b4d41c3bea11c67f7da88d377a0998f5222355f2140e0ec08ee9573e982ce035a5012552c5525063c3f47ad80507bade8c1252892792b9bd925e8e1b44b0eaa
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Rumors::Api::Client
|
2
2
|
|
3
|
-
|
3
|
+
All credit belongs to [@cofacts](https://github.com/cofacts), appreciate all efforts they have done from time to time for the line rumors.
|
4
4
|
|
5
|
-
|
5
|
+
This Ruby api Client which is based on Cofacts database and the provided GraphQL, to let you search high relevant rumor results easily.
|
6
|
+
|
7
|
+
Visit [真的假的 Cofacts](https://beta.hackfoldr.org/cofacts), to become one of contributors!
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -41,7 +43,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
41
43
|
|
42
44
|
## Contributing
|
43
45
|
|
44
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/carolhsu/rumors-api-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
45
47
|
|
46
48
|
## License
|
47
49
|
|
data/bin/console
CHANGED
@@ -7,8 +7,8 @@ require "rumors/api/client"
|
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
|
11
|
-
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
12
|
|
13
13
|
require "irb"
|
14
14
|
IRB.start(__FILE__)
|
@@ -28,8 +28,11 @@ module Rumors
|
|
28
28
|
most_like = calculate_similarity(contents)
|
29
29
|
return unless most_like[:score] > SIMILARITY
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
find_article(most_like[:article_id])
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_article(article_id)
|
35
|
+
@articles['data']['ListArticles']['edges'].select { |h, v| h['node']['id'] == article_id }.first['node']
|
33
36
|
end
|
34
37
|
|
35
38
|
def parse_content
|
@@ -44,7 +47,7 @@ module Rumors
|
|
44
47
|
# NOTE: https://github.com/jpmckinney/tf-idf-similarity
|
45
48
|
most_like = {
|
46
49
|
article_id: '',
|
47
|
-
score: 0
|
50
|
+
score: 0
|
48
51
|
}
|
49
52
|
|
50
53
|
original_text = TfIdfSimilarity::Document.new(@text)
|
@@ -84,9 +87,11 @@ module Rumors
|
|
84
87
|
end
|
85
88
|
|
86
89
|
def build_body(util, argument)
|
87
|
-
|
90
|
+
current_util_class = "rumors/api/client/utils/#{util}".classify
|
91
|
+
current_util = Object.const_get(current_util_class).new(argument)
|
88
92
|
{
|
89
|
-
query:
|
93
|
+
query: current_util.purify_gql_query,
|
94
|
+
variables: current_util.variables
|
90
95
|
}
|
91
96
|
end
|
92
97
|
end
|
@@ -11,23 +11,35 @@ module Rumors
|
|
11
11
|
gql_query.strip
|
12
12
|
end
|
13
13
|
|
14
|
+
def variables
|
15
|
+
{ text: @text.to_s }
|
16
|
+
end
|
17
|
+
|
14
18
|
private
|
15
19
|
|
16
20
|
def gql_query
|
17
21
|
<<-GQL
|
18
|
-
{
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
query($text: String) {
|
23
|
+
ListArticles(
|
24
|
+
filter: { moreLikeThis: { like: $text } }
|
25
|
+
orderBy: [{ _score: DESC }]
|
26
|
+
first: 4
|
27
|
+
) {
|
28
|
+
edges {
|
29
|
+
node {
|
30
|
+
id
|
31
|
+
text
|
32
|
+
articleReplies {
|
33
|
+
reply {
|
34
|
+
id
|
35
|
+
text
|
36
|
+
type
|
37
|
+
reference
|
38
|
+
}
|
29
39
|
}
|
30
|
-
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
31
43
|
}
|
32
44
|
GQL
|
33
45
|
end
|
data/lib/rumors/api/client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumors-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carol H
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -134,7 +134,6 @@ files:
|
|
134
134
|
- ".travis.yml"
|
135
135
|
- CODE_OF_CONDUCT.md
|
136
136
|
- Gemfile
|
137
|
-
- Gemfile.lock
|
138
137
|
- LICENSE.txt
|
139
138
|
- README.md
|
140
139
|
- Rakefile
|
@@ -142,11 +141,8 @@ files:
|
|
142
141
|
- bin/setup
|
143
142
|
- lib/rumors/api/client.rb
|
144
143
|
- lib/rumors/api/client/base.rb
|
145
|
-
- lib/rumors/api/client/utils/get_article_and_replies.rb
|
146
144
|
- lib/rumors/api/client/utils/list_articles.rb
|
147
145
|
- lib/rumors/api/client/version.rb
|
148
|
-
- rumors-api-client-0.1.1.gem
|
149
|
-
- rumors-api-client-0.1.2.gem
|
150
146
|
- rumors-api-client.gemspec
|
151
147
|
homepage: https://github.com/carolhsu/rumors-api-client
|
152
148
|
licenses:
|
@@ -168,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
164
|
version: '0'
|
169
165
|
requirements: []
|
170
166
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.7.
|
167
|
+
rubygems_version: 2.7.3
|
172
168
|
signing_key:
|
173
169
|
specification_version: 4
|
174
170
|
summary: a api client to "https://cofacts.g0v.tw/"
|
data/Gemfile.lock
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rumors-api-client (0.1.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.5.2)
|
10
|
-
public_suffix (>= 2.0.2, < 4.0)
|
11
|
-
coderay (1.1.2)
|
12
|
-
crack (0.4.3)
|
13
|
-
safe_yaml (~> 1.0.0)
|
14
|
-
diff-lcs (1.3)
|
15
|
-
hashdiff (0.3.7)
|
16
|
-
httparty (0.16.3)
|
17
|
-
mime-types (~> 3.0)
|
18
|
-
multi_xml (>= 0.5.2)
|
19
|
-
method_source (0.9.2)
|
20
|
-
mime-types (3.2.2)
|
21
|
-
mime-types-data (~> 3.2015)
|
22
|
-
mime-types-data (3.2018.0812)
|
23
|
-
multi_xml (0.6.0)
|
24
|
-
pry (0.12.2)
|
25
|
-
coderay (~> 1.1.0)
|
26
|
-
method_source (~> 0.9.0)
|
27
|
-
public_suffix (3.0.3)
|
28
|
-
rake (10.5.0)
|
29
|
-
rspec (3.8.0)
|
30
|
-
rspec-core (~> 3.8.0)
|
31
|
-
rspec-expectations (~> 3.8.0)
|
32
|
-
rspec-mocks (~> 3.8.0)
|
33
|
-
rspec-core (3.8.0)
|
34
|
-
rspec-support (~> 3.8.0)
|
35
|
-
rspec-expectations (3.8.2)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.8.0)
|
38
|
-
rspec-mocks (3.8.0)
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.8.0)
|
41
|
-
rspec-support (3.8.0)
|
42
|
-
safe_yaml (1.0.4)
|
43
|
-
tf-idf-similarity (0.1.6)
|
44
|
-
unicode_utils (~> 1.4)
|
45
|
-
unicode_utils (1.4.0)
|
46
|
-
vcr (4.0.0)
|
47
|
-
webmock (3.4.2)
|
48
|
-
addressable (>= 2.3.6)
|
49
|
-
crack (>= 0.3.2)
|
50
|
-
hashdiff
|
51
|
-
|
52
|
-
PLATFORMS
|
53
|
-
ruby
|
54
|
-
|
55
|
-
DEPENDENCIES
|
56
|
-
bundler (~> 1.16)
|
57
|
-
httparty (~> 0.16)
|
58
|
-
pry (~> 0.12)
|
59
|
-
rake (~> 10.0)
|
60
|
-
rspec (~> 3.0)
|
61
|
-
rumors-api-client!
|
62
|
-
tf-idf-similarity (~> 0.1)
|
63
|
-
vcr (~> 4.0)
|
64
|
-
webmock (~> 3.4)
|
65
|
-
|
66
|
-
BUNDLED WITH
|
67
|
-
1.16.1
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Rumors
|
2
|
-
module Api
|
3
|
-
module Client
|
4
|
-
module Utils
|
5
|
-
class GetArticleAndReplies
|
6
|
-
def initialize(id)
|
7
|
-
@id = id
|
8
|
-
end
|
9
|
-
|
10
|
-
def purify_gql_query
|
11
|
-
gql_query.strip
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def gql_query
|
17
|
-
<<-GQL
|
18
|
-
{
|
19
|
-
GetArticle(id: "#{@id}") {
|
20
|
-
id
|
21
|
-
text
|
22
|
-
articleReplies {
|
23
|
-
reply {
|
24
|
-
id
|
25
|
-
text
|
26
|
-
type
|
27
|
-
reference
|
28
|
-
}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
GQL
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/rumors-api-client-0.1.1.gem
DELETED
Binary file
|
data/rumors-api-client-0.1.2.gem
DELETED
Binary file
|