sentimeta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +2 -0
- data/LICENCE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/config/endpoint.yml +5 -0
- data/lib/sentimeta/client.rb +37 -0
- data/lib/sentimeta/error/unreachable.rb +11 -0
- data/lib/sentimeta/model.rb +29 -0
- data/lib/sentimeta/version.rb +3 -0
- data/lib/sentimeta.rb +36 -0
- data/sentimeta.gemspec +16 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03b523382194d9a1dc3d6148b04feef2d7fd5014
|
4
|
+
data.tar.gz: 3e14c6eb60732935c166558446330879dc652387
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb1c7b31e955c86605412398e6ae6daa1e0a91990170b23bf0e63764b650ddce00d8c5317ec76ac357ca74b10f13685c0fec49f2fa01ae02b047085ad2b6a6c8
|
7
|
+
data.tar.gz: be898aaff8c1d2728cd92da3a8732a39d2d42c4db71762a544fe03a6639384aa2221e9b7b032fe45cb42d98776671b5be9636ff2d5dee4926c2396532c095028
|
data/Gemfile
ADDED
data/LICENCE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Artem Shpakov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Sentimeta
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'sentimeta'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
Sentimeta.env = :staging # :production is default
|
17
|
+
Sentimeta.lang = :en # default is I18n.locale if defined
|
18
|
+
|
19
|
+
# client can be used directly (fetch criteria, spheres & objects)
|
20
|
+
spheres = Sentimeta::Client.spheres
|
21
|
+
Sentimeta.sphere = spheres.first['name'] # pick a specific sphere
|
22
|
+
|
23
|
+
# or via subclassing Sentimeta::Model
|
24
|
+
class Criterion < Sentimeta::Model
|
25
|
+
endpoint :criteria # send requests to /api/v1/#{Sentimeta.sphere}/criteria
|
26
|
+
attr_accessor :name, :label, :subcriteria
|
27
|
+
|
28
|
+
def self.all
|
29
|
+
fetch subcriteria: true
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.leafs options
|
33
|
+
all(options).flat_map do |root|
|
34
|
+
root['subcriteria'].map { |sub| new sub }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
criteria = Criterion.leafs # an array of Criterion class instances
|
40
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config/endpoint.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
|
5
|
+
module Sentimeta
|
6
|
+
module Client
|
7
|
+
|
8
|
+
class << self
|
9
|
+
%i(criteria spheres objects).each do |endpoint|
|
10
|
+
define_method endpoint do |options={}|
|
11
|
+
fetch(endpoint, options)[endpoint.to_s]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch endpoint, options={}
|
16
|
+
url = [].tap do |components|
|
17
|
+
components << Sentimeta.endpoint
|
18
|
+
components << (Sentimeta.sphere || options.delete(:sphere)) if endpoint != :spheres
|
19
|
+
components << endpoint
|
20
|
+
components << options.delete(:id)
|
21
|
+
end.compact.join('/')
|
22
|
+
|
23
|
+
uri = URI.parse url
|
24
|
+
uri.query = URI.encode_www_form(p: options.reverse_merge(lang: Sentimeta.lang).to_json)
|
25
|
+
Sentimeta.logger.debug " Sentimeta: #{ URI.unescape uri.to_s }"
|
26
|
+
|
27
|
+
|
28
|
+
begin
|
29
|
+
JSON.parse(uri.open.read)
|
30
|
+
rescue
|
31
|
+
raise Sentimeta::Error::Unreachable
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Sentimeta
|
2
|
+
class Model
|
3
|
+
|
4
|
+
def initialize params = {}
|
5
|
+
(params || {}).each do |key, value|
|
6
|
+
method = "#{key}="
|
7
|
+
public_send(method, value) if respond_to?(method)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def self.endpoint endpoint
|
13
|
+
@endpoint = endpoint
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def self.fetch options={}
|
20
|
+
response = Sentimeta::Client.public_send @endpoint, options
|
21
|
+
if response.kind_of? Array
|
22
|
+
response.map { |entry| new entry }
|
23
|
+
elsif response.kind_of? Hash
|
24
|
+
new response
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/sentimeta.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Sentimeta
|
2
|
+
|
3
|
+
require "sentimeta/version"
|
4
|
+
require "sentimeta/client"
|
5
|
+
require "sentimeta/model"
|
6
|
+
require "sentimeta/error/unreachable"
|
7
|
+
|
8
|
+
require 'logger'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :env, :sphere
|
12
|
+
attr_writer :endpoint, :lang
|
13
|
+
|
14
|
+
def endpoint
|
15
|
+
@endpoint ||= begin
|
16
|
+
config_path = File.join(File.dirname(File.expand_path(__FILE__)), '../config/endpoint.yml')
|
17
|
+
config = YAML.load_file(config_path)[env.to_s].symbolize_keys
|
18
|
+
config[:url]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def lang
|
23
|
+
if defined?(::I18n) and ::I18n.respond_to?(:locale)
|
24
|
+
self.lang = I18n.locale
|
25
|
+
end
|
26
|
+
@lang || :en
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger
|
30
|
+
@logger ||= Logger.new STDOUT
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
self.env = :production
|
35
|
+
|
36
|
+
end
|
data/sentimeta.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'sentimeta/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'sentimeta'
|
7
|
+
s.version = Sentimeta::VERSION
|
8
|
+
s.summary = "Sentimeta API client"
|
9
|
+
s.authors = ["Artem Shpakov"]
|
10
|
+
s.email = 'artyom.shpakov@sentimeta.com'
|
11
|
+
s.homepage = ""
|
12
|
+
s.license = "MIT"
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.add_development_dependency "bundler", "~> 1.5"
|
15
|
+
s.add_development_dependency "rake"
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sentimeta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artem Shpakov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-08 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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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
|
+
description:
|
42
|
+
email: artyom.shpakov@sentimeta.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- ".gitignore"
|
48
|
+
- Gemfile
|
49
|
+
- LICENCE.txt
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- config/endpoint.yml
|
53
|
+
- lib/sentimeta.rb
|
54
|
+
- lib/sentimeta/client.rb
|
55
|
+
- lib/sentimeta/error/unreachable.rb
|
56
|
+
- lib/sentimeta/model.rb
|
57
|
+
- lib/sentimeta/version.rb
|
58
|
+
- sentimeta.gemspec
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Sentimeta API client
|
83
|
+
test_files: []
|