sentimeta 0.0.1 → 0.0.2
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/.rspec +2 -0
- data/README.md +11 -8
- data/Rakefile +3 -0
- data/config/endpoint.yml +1 -1
- data/lib/sentimeta/client.rb +13 -6
- data/lib/sentimeta/version.rb +1 -1
- data/lib/sentimeta.rb +2 -2
- data/sentimeta.gemspec +2 -0
- data/spec/client_spec.rb +48 -0
- data/spec/model_spec.rb +23 -0
- data/spec/spec_helper.rb +15 -0
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0374f164fb37ea00358050a3f867747cbcf68781
|
4
|
+
data.tar.gz: 30d9090b1554c07228f989c0ddc977d8dab7c9f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a08d37a4b66f78d92c0683f495de4fa141d9885622e6ecb7f4e86a2b2214c4a292a4bac682c9d0dba552462e0f4f1250f330fcb926059706027521ee5b80f7a
|
7
|
+
data.tar.gz: 0faff4f50fa2439b4f001ede137dfedae90ac14aebc8c385a0af351c21028b8b2cc5c6e886e8f006235872233178c7ae0ab87b99dea9f39cc45ce1e4ac332455
|
data/.rspec
ADDED
data/README.md
CHANGED
@@ -15,11 +15,11 @@ And then execute:
|
|
15
15
|
```ruby
|
16
16
|
Sentimeta.env = :staging # :production is default
|
17
17
|
Sentimeta.lang = :en # default is I18n.locale if defined
|
18
|
-
|
19
|
-
# client can be used directly (fetch criteria, spheres & objects)
|
18
|
+
|
19
|
+
# client can be used directly (fetch criteria, spheres, catalog & objects)
|
20
20
|
spheres = Sentimeta::Client.spheres
|
21
21
|
Sentimeta.sphere = spheres.first['name'] # pick a specific sphere
|
22
|
-
|
22
|
+
|
23
23
|
# or via subclassing Sentimeta::Model
|
24
24
|
class Criterion < Sentimeta::Model
|
25
25
|
endpoint :criteria # send requests to /api/v1/#{Sentimeta.sphere}/criteria
|
@@ -28,13 +28,16 @@ class Criterion < Sentimeta::Model
|
|
28
28
|
def self.all
|
29
29
|
fetch subcriteria: true
|
30
30
|
end
|
31
|
-
|
32
|
-
def self.leafs
|
33
|
-
all
|
34
|
-
root
|
31
|
+
|
32
|
+
def self.leafs
|
33
|
+
all.flat_map do |root|
|
34
|
+
root.subcriteria.map { |sub| new sub }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
criteria = Criterion.leafs # an array of Criterion class instances
|
40
|
+
|
41
|
+
# to fetch raw data
|
42
|
+
presets = Sentimeta::Client.fetch :infotext, {subcriteria: true, design: "std", param: "main", lang: "en"}
|
40
43
|
```
|
data/Rakefile
CHANGED
data/config/endpoint.yml
CHANGED
data/lib/sentimeta/client.rb
CHANGED
@@ -6,25 +6,32 @@ module Sentimeta
|
|
6
6
|
module Client
|
7
7
|
|
8
8
|
class << self
|
9
|
-
%i(criteria spheres objects).each do |endpoint|
|
9
|
+
%i(criteria spheres objects catalog).each do |endpoint|
|
10
10
|
define_method endpoint do |options={}|
|
11
|
-
fetch(endpoint, options)[endpoint.to_s]
|
11
|
+
Sentimeta::Client.fetch(endpoint, options)[endpoint.to_s]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def fetch endpoint, options={}
|
16
|
+
send_request generate_uri endpoint, options
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_uri endpoint, options={}
|
16
20
|
url = [].tap do |components|
|
17
21
|
components << Sentimeta.endpoint
|
18
|
-
components << (
|
22
|
+
components << (options.delete(:sphere) || Sentimeta.sphere) unless endpoint == :spheres
|
19
23
|
components << endpoint
|
20
24
|
components << options.delete(:id)
|
21
25
|
end.compact.join('/')
|
22
26
|
|
23
27
|
uri = URI.parse url
|
24
|
-
uri.query = URI.encode_www_form(p: options.reverse_merge(lang: Sentimeta.lang).to_json)
|
25
|
-
|
26
|
-
|
28
|
+
# uri.query = URI.encode_www_form(p: options.reverse_merge(lang: Sentimeta.lang).to_json)
|
29
|
+
uri.query = URI.encode_www_form(p: options.merge(lang: Sentimeta.lang).to_json)
|
30
|
+
uri
|
31
|
+
end
|
27
32
|
|
33
|
+
def send_request uri
|
34
|
+
# Sentimeta.logger.debug " Sentimeta: #{ URI.unescape uri.to_s }"
|
28
35
|
begin
|
29
36
|
JSON.parse(uri.open.read)
|
30
37
|
rescue
|
data/lib/sentimeta/version.rb
CHANGED
data/lib/sentimeta.rb
CHANGED
@@ -14,8 +14,8 @@ module Sentimeta
|
|
14
14
|
def endpoint
|
15
15
|
@endpoint ||= begin
|
16
16
|
config_path = File.join(File.dirname(File.expand_path(__FILE__)), '../config/endpoint.yml')
|
17
|
-
config = YAML.load_file(config_path)[env.to_s]
|
18
|
-
config[
|
17
|
+
config = YAML.load_file(config_path)[env.to_s]
|
18
|
+
config['url']
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/sentimeta.gemspec
CHANGED
@@ -13,4 +13,6 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.add_development_dependency "bundler", "~> 1.5"
|
15
15
|
s.add_development_dependency "rake"
|
16
|
+
s.add_development_dependency "rspec", "~> 3.1.0"
|
17
|
+
s.add_development_dependency "fakeweb", "~> 1.3"
|
16
18
|
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sentimeta::Client do
|
4
|
+
|
5
|
+
subject { Sentimeta::Client }
|
6
|
+
|
7
|
+
let(:valid_url) { subject.generate_uri(:spheres) }
|
8
|
+
|
9
|
+
|
10
|
+
describe :fetch do
|
11
|
+
it { should respond_to :fetch }
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe :generate_uri do
|
16
|
+
it "should return an instance of URI" do
|
17
|
+
expect(valid_url).to be_kind_of URI
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
describe :send_request do
|
23
|
+
it "should be fine for a valid uri" do
|
24
|
+
expect { subject.send_request valid_url }.not_to raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise an error for invalid uri" do
|
28
|
+
expect { subject.send_request "invalid" }.to raise_error Sentimeta::Error::Unreachable
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
describe :endpoints do
|
34
|
+
%i(criteria spheres objects catalog).each do |endpoint|
|
35
|
+
it { should respond_to endpoint }
|
36
|
+
|
37
|
+
it "##{endpoint} should call fetch once" do
|
38
|
+
expect(subject).to receive(:fetch).and_call_original.once
|
39
|
+
subject.public_send endpoint
|
40
|
+
end
|
41
|
+
|
42
|
+
it "##{endpoint} should return an array" do
|
43
|
+
expect(subject.public_send endpoint).to be_kind_of Array
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sentimeta::Model do
|
4
|
+
|
5
|
+
subject(:client) { Sentimeta::Client }
|
6
|
+
subject { model = Sentimeta::Model; model.endpoint :spheres; model }
|
7
|
+
|
8
|
+
it { should respond_to :fetch }
|
9
|
+
|
10
|
+
|
11
|
+
describe :fetch do
|
12
|
+
|
13
|
+
it "should return an array" do
|
14
|
+
expect(subject.send :fetch).to be_kind_of Array
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should call client_fetch once" do
|
18
|
+
expect(client).to receive(:fetch).and_call_original.once
|
19
|
+
subject.send :fetch
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
require 'sentimeta'
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
Sentimeta.sphere = :hotels
|
8
|
+
|
9
|
+
require 'fakeweb'
|
10
|
+
|
11
|
+
%i(criteria spheres objects catalog).each do |endpoint|
|
12
|
+
FakeWeb.register_uri(:get,
|
13
|
+
Sentimeta::Client.generate_uri(endpoint).to_s,
|
14
|
+
body: "{\"lang\": \"en\", \"#{endpoint}\": [{\"label\": \"label\", \"name\": \"name\"}], \"ver\": 1}")
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentimeta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Shpakov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
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.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fakeweb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
41
69
|
description:
|
42
70
|
email: artyom.shpakov@sentimeta.com
|
43
71
|
executables: []
|
@@ -45,6 +73,7 @@ extensions: []
|
|
45
73
|
extra_rdoc_files: []
|
46
74
|
files:
|
47
75
|
- ".gitignore"
|
76
|
+
- ".rspec"
|
48
77
|
- Gemfile
|
49
78
|
- LICENCE.txt
|
50
79
|
- README.md
|
@@ -56,6 +85,9 @@ files:
|
|
56
85
|
- lib/sentimeta/model.rb
|
57
86
|
- lib/sentimeta/version.rb
|
58
87
|
- sentimeta.gemspec
|
88
|
+
- spec/client_spec.rb
|
89
|
+
- spec/model_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
59
91
|
homepage: ''
|
60
92
|
licenses:
|
61
93
|
- MIT
|