meaning-cloud 0.1.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 +7 -0
- data/Rakefile +14 -0
- data/lib/meaning_cloud.rb +26 -0
- data/lib/meaning_cloud/topics.rb +23 -0
- data/spec/lib/meaning_cloud/topics_spec.rb +30 -0
- data/spec/lib/meaning_cloud_spec.rb +22 -0
- data/spec/spec_helper.rb +16 -0
- metadata +128 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 8bb476db659b7be477042c9e8133214fc865b74e
|
|
4
|
+
data.tar.gz: a9144be6636c66e2d119fdb4c730746f79c40e50
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b3d95976bed9d3d776bdb45c352fc37680a417e1f0d07249ac283ffef1d7f0a517e7bc828cdcf9ad97802cb0b0eaca47085c32d465c5cfc85194085f7e14f8f1
|
|
7
|
+
data.tar.gz: e6931227a23276dc5a0f5c72382f3b39edbb23f5d109e9c585ef1d06541c337bbec57a41ffe84e8648b077592ae330fa524612da930e970341a87cad154dd1f5
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'bundler'
|
|
2
|
+
Bundler::GemHelper.install_tasks
|
|
3
|
+
|
|
4
|
+
$:.unshift 'lib'
|
|
5
|
+
|
|
6
|
+
desc 'Default: run unit tests.'
|
|
7
|
+
task :default => [:spec]
|
|
8
|
+
|
|
9
|
+
require 'rspec/core/rake_task'
|
|
10
|
+
|
|
11
|
+
desc 'Run specs'
|
|
12
|
+
RSpec::Core::RakeTask.new do |t|
|
|
13
|
+
t.pattern = './spec/**/*_spec.rb'
|
|
14
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
require 'meaning_cloud/topics'
|
|
4
|
+
|
|
5
|
+
# Top level name space for the entire Gem.
|
|
6
|
+
module MeaningCloud
|
|
7
|
+
API_BASE = 'https://api.meaningcloud.com/topics-1.2.php'
|
|
8
|
+
|
|
9
|
+
def self.configuration
|
|
10
|
+
@configuration ||= Configuration.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.configure
|
|
14
|
+
self.configuration ||= Configuration.new
|
|
15
|
+
yield(configuration) if block_given?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Main configuration class.
|
|
19
|
+
class Configuration
|
|
20
|
+
attr_accessor :key
|
|
21
|
+
|
|
22
|
+
def initialize
|
|
23
|
+
@key = nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module MeaningCloud
|
|
2
|
+
# A class to hold all topic extraction related code.
|
|
3
|
+
class Topics
|
|
4
|
+
def self.extract_topics(options = nil)
|
|
5
|
+
fail(Exception, 'Missing key') if MeaningCloud.configuration.key.nil?
|
|
6
|
+
|
|
7
|
+
options ||= {}
|
|
8
|
+
|
|
9
|
+
options = {
|
|
10
|
+
of: :json,
|
|
11
|
+
key: MeaningCloud.configuration.key,
|
|
12
|
+
lang: :en,
|
|
13
|
+
tt: 'ec',
|
|
14
|
+
uw: 'y'
|
|
15
|
+
}.merge(options)
|
|
16
|
+
|
|
17
|
+
query = URI.encode_www_form(options)
|
|
18
|
+
|
|
19
|
+
result = RestClient.post("#{API_BASE}?#{query}", {})
|
|
20
|
+
JSON.parse(result)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MeaningCloud::Topics do
|
|
4
|
+
after :each do
|
|
5
|
+
MeaningCloud.configuration.key = nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'raises an error on empty key' do
|
|
9
|
+
MeaningCloud.configuration.key = nil
|
|
10
|
+
expect { MeaningCloud::Topics.extract_topics(txt: Faker::Company.bs) }.to raise_error(Exception)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'sends a proper request' do
|
|
14
|
+
result = "{\"status\":{\"code\":\"0\",\"msg\":\"OK\",\"credits\":\"1\",\"remaining_credits\":\"39993\"},\"entity_list\":[],\"concept_list\":[]}"
|
|
15
|
+
key = SecureRandom.uuid
|
|
16
|
+
MeaningCloud.configuration.key = key
|
|
17
|
+
|
|
18
|
+
txt = Faker::Company.bs
|
|
19
|
+
|
|
20
|
+
expect(RestClient).to receive(
|
|
21
|
+
:post
|
|
22
|
+
).with(
|
|
23
|
+
"https://api.meaningcloud.com/topics-1.2.php?of=json&key=#{key}&lang=en&tt=ec&uw=y&txt=#{txt.gsub(' ', '+')}", {}
|
|
24
|
+
).and_return(
|
|
25
|
+
result
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
expect(MeaningCloud::Topics.extract_topics(txt: txt)).to eq(JSON.parse(result))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe MeaningCloud do
|
|
4
|
+
after :each do
|
|
5
|
+
MeaningCloud.configuration.key = nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'has the correct default' do
|
|
9
|
+
expect(MeaningCloud.configuration.key).to be nil
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'sets the correct configuration' do
|
|
13
|
+
expect(MeaningCloud.configuration.key).to be nil
|
|
14
|
+
|
|
15
|
+
key = SecureRandom.uuid
|
|
16
|
+
MeaningCloud.configure do |config|
|
|
17
|
+
config.key = key
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
expect(MeaningCloud.configuration.key).to equal(key)
|
|
21
|
+
end
|
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'codeclimate-test-reporter'
|
|
2
|
+
CodeClimate::TestReporter.start
|
|
3
|
+
|
|
4
|
+
require 'bundler/setup'
|
|
5
|
+
require 'meaning_cloud'
|
|
6
|
+
require 'pry'
|
|
7
|
+
require 'faker'
|
|
8
|
+
require 'json'
|
|
9
|
+
|
|
10
|
+
# require_relative 'support/fakes'
|
|
11
|
+
|
|
12
|
+
RSpec.configure do |config|
|
|
13
|
+
config.disable_monkey_patching!
|
|
14
|
+
config.formatter = 'documentation'
|
|
15
|
+
config.color = true
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: meaning-cloud
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nadav Shatz
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rest-client
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.1'
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: 3.1.0
|
|
51
|
+
type: :development
|
|
52
|
+
prerelease: false
|
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - "~>"
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '3.1'
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 3.1.0
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: faker
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: semver
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
description: A Gem to expose a wrapping API for the Meaning Cloud API's
|
|
90
|
+
email: nadav@tailorbrands.com
|
|
91
|
+
executables: []
|
|
92
|
+
extensions: []
|
|
93
|
+
extra_rdoc_files: []
|
|
94
|
+
files:
|
|
95
|
+
- Rakefile
|
|
96
|
+
- lib/meaning_cloud.rb
|
|
97
|
+
- lib/meaning_cloud/topics.rb
|
|
98
|
+
- spec/lib/meaning_cloud/topics_spec.rb
|
|
99
|
+
- spec/lib/meaning_cloud_spec.rb
|
|
100
|
+
- spec/spec_helper.rb
|
|
101
|
+
homepage: https://github.com/TailorBrands/meaning-cloud
|
|
102
|
+
licenses:
|
|
103
|
+
- MIT
|
|
104
|
+
metadata: {}
|
|
105
|
+
post_install_message:
|
|
106
|
+
rdoc_options: []
|
|
107
|
+
require_paths:
|
|
108
|
+
- lib
|
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
|
+
requirements:
|
|
116
|
+
- - ">="
|
|
117
|
+
- !ruby/object:Gem::Version
|
|
118
|
+
version: '0'
|
|
119
|
+
requirements: []
|
|
120
|
+
rubyforge_project:
|
|
121
|
+
rubygems_version: 2.4.5
|
|
122
|
+
signing_key:
|
|
123
|
+
specification_version: 4
|
|
124
|
+
summary: An API wrapper for Meaning Cloud API's
|
|
125
|
+
test_files:
|
|
126
|
+
- spec/lib/meaning_cloud/topics_spec.rb
|
|
127
|
+
- spec/lib/meaning_cloud_spec.rb
|
|
128
|
+
- spec/spec_helper.rb
|