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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bca530d28062816527adb522bbda6cd9f2944997dd49254814149c3f2626889
4
- data.tar.gz: ad1de186a7be84c5fb643ca1c29d0057e88efd02b4c68d31a261aef498532713
3
+ metadata.gz: e01c7b9c0baec0166aa6dbd36e44d1c9598a7dac1c51bc34eb8c3128d06bae65
4
+ data.tar.gz: 6fa1296b339fcb393c978796e15fdcbf6e4e115ba012fa3b05a2324b37bc752b
5
5
  SHA512:
6
- metadata.gz: daac90d5aa4351868c3b051228b56fd8bd28fbb9a860be1ddbaf0d99859b1d45599880947e39cad19661badb3ea943f378f2ba3ec742c46b3e92ba122042a5f1
7
- data.tar.gz: 5aa497598b5c7f30faca862e0c9da7fdeceefc8486c93740531d920e7eba56b69300bee731622b51ed03e42f98da6e2713264aea9004b82f2acee0d5642ef51a
6
+ metadata.gz: '090d5f3963c7e08b457678a3d5e14d8af9d6e232794bbf83838d72530bf6d317f8cad9cb0752a302ed3d1e2972db65925505723a1e86655af134f036b709e6a2'
7
+ data.tar.gz: 5b4d41c3bea11c67f7da88d377a0998f5222355f2140e0ec08ee9573e982ce035a5012552c5525063c3f47ad80507bade8c1252892792b9bd925e8e1b44b0eaa
data/.gitignore CHANGED
@@ -9,3 +9,7 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ tags
14
+ *.gem
15
+ Gemfile.lock
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Rumors::Api::Client
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rumors/api/client`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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/[USERNAME]/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.
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
- # require "pry"
11
- # Pry.start
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
- body = build_body('get_article_and_replies', most_like[:article_id])
32
- post_request(body)
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
- current_util = "rumors/api/client/utils/#{util}".classify
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: eval(current_util).new(argument).purify_gql_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
- ListArticles(
20
- filter: { moreLikeThis: { like: "#{@text}" } }
21
- orderBy: [{ _score: DESC }]
22
- first: 4
23
- ) {
24
- edges {
25
- node {
26
- id
27
- text
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
@@ -1,7 +1,7 @@
1
1
  module Rumors
2
2
  module Api
3
3
  module Client
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -6,7 +6,6 @@ require "json"
6
6
  require "rumors/api/client/version"
7
7
  require "rumors/api/client/base"
8
8
  require "rumors/api/client/utils/list_articles"
9
- require "rumors/api/client/utils/get_article_and_replies"
10
9
 
11
10
  module Rumors
12
11
  module Api
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.1.3
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: 2018-12-21 00:00:00.000000000 Z
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.6
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
Binary file
Binary file