sentimeta 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: a11776a8666b48bfd302b9cdec9483a268eef114
4
- data.tar.gz: 6a13baf8f7370768a8d6d18acdc8a0ab414c7220
3
+ metadata.gz: 431cbeb69e0bf92505b1bf5687050247e9292233
4
+ data.tar.gz: da305f3372a3c2686abd905938102c339cf06a84
5
5
  SHA512:
6
- metadata.gz: c674d811c2ede6c546856e20f8b5cac41251a3572c96af97a2c0c0ef3288f5a41b8e0679623bcd30d72aca9e869cd99f708acd2452302889284cadfff73d9c36
7
- data.tar.gz: 2807c37d1e134f3e70c8b02fcae9f5df3cc8d03be631fcb0ed0d55e24650763ebcfb41a6f5946cf9080b6efda4e7edb71cbfc93e20a0fa80ab86937d8085cd84
6
+ metadata.gz: 45be246f83d067969cda6a4cb8e25be9c786308235543434d77d35777b3b5e4d8ce38f1a4099206443b49a67f0b6f3bb50b5f2cbc0c6a0d645cd9612571855c2
7
+ data.tar.gz: 4578f03407e0a64cc73c5249dfe8e4269f4d9e861a60f0fe37ab4b8c99bf82bc281d10c69c0712109a6f1e2d820b650e2064963913a6298c56f9c90545883922
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  .bundle
4
4
  Gemfile.lock
5
5
  pkg
6
+ fixtures
@@ -2,19 +2,33 @@ module Sentimeta::Client::Auth
2
2
  extend self
3
3
  extend Sentimeta::RestClient
4
4
 
5
- def namespace
6
- :auth
7
- end
5
+ self.namespace = 'crowd/auth'
8
6
 
9
7
  def user token
10
- get :users, id: token
8
+ get 'users/token', id: token
11
9
  end
12
10
 
13
11
  def signup attrs
14
- post :users, user: attrs
12
+ post :signup, attrs
15
13
  end
16
14
 
17
15
  def signin attrs
18
- post :sessions, user: attrs
16
+ post :signin, attrs
17
+ end
18
+
19
+ def reset_password_token login
20
+ put 'users/create_reset_token', login: login
21
+ end
22
+
23
+ def reset_password params
24
+ put 'users/reset_password', params
25
+ end
26
+
27
+ def oauth attrs
28
+ post :oauth, attrs
29
+ end
30
+
31
+ def signout token
32
+ delete 'users/token', id: token
19
33
  end
20
34
  end
@@ -1,6 +1,9 @@
1
1
  module Sentimeta::Client::Data
2
2
  extend self
3
3
  extend Sentimeta::RestClient
4
+
5
+ def sphere() Sentimeta.sphere end
6
+
4
7
 
5
8
  %i(criteria spheres objects catalog).each do |endpoint|
6
9
  define_method endpoint do |options={}|
@@ -2,26 +2,29 @@ require 'json'
2
2
  require "colorize"
3
3
  require "rest_client"
4
4
 
5
-
6
5
  module Sentimeta
7
6
  module RestClient
8
7
  require "sentimeta/error/unreachable"
9
8
  # require "sentimeta/error/record_not_found"
10
9
 
10
+ attr_accessor :namespace
11
+
11
12
 
12
13
  class ApiResponse
13
14
  attr_accessor :status, :body
14
15
 
15
16
  def initialize response
16
17
  self.status = response.code
17
- self.body = JSON.parse(response)
18
+ self.body = JSON.parse(response) rescue nil
18
19
  end
19
20
 
20
21
  def ok?
21
22
  status < 300
22
23
  end
23
24
 
24
- delegate :[], to: :body
25
+ def [] key
26
+ body[key] if body.respond_to?(:[])
27
+ end
25
28
  end
26
29
 
27
30
 
@@ -59,14 +62,11 @@ module Sentimeta
59
62
  end
60
63
  end
61
64
 
62
-
63
- private
64
-
65
65
  def generate_uri endpoint, options={}
66
66
  [].tap do |components|
67
67
  components << Sentimeta.endpoint
68
- components << (options.delete(:sphere) || Sentimeta.sphere) unless endpoint == :spheres
69
- components << namespace if respond_to?(:namespace)
68
+ components << (options.delete(:sphere) || try(:sphere)) unless endpoint == :spheres
69
+ components << namespace unless namespace.nil?
70
70
  components << endpoint
71
71
  components << options.delete(:filter) if endpoint == :attributes # TODO remove
72
72
  components << options.delete(:provider) if endpoint == :prices # TODO remove
@@ -0,0 +1,74 @@
1
+ class Object
2
+ def try(*a, &b)
3
+ if a.empty? && block_given?
4
+ yield self
5
+ else
6
+ public_send(*a, &b) if respond_to?(a.first)
7
+ end
8
+ end
9
+ end
10
+
11
+ class String
12
+ def blank?
13
+ strip == ''
14
+ end
15
+
16
+ def present?
17
+ !blank?
18
+ end
19
+ end
20
+
21
+ class Array
22
+ def blank?
23
+ empty?
24
+ end
25
+ def empty?
26
+ self == []
27
+ end
28
+
29
+ def present?
30
+ !empty?
31
+ end
32
+ end
33
+
34
+ class Fixnum
35
+ def present?
36
+ true
37
+ end
38
+
39
+ def blank?
40
+ false
41
+ end
42
+ end
43
+
44
+ class NilClass
45
+ def present?
46
+ false
47
+ end
48
+
49
+ def blank?
50
+ true
51
+ end
52
+
53
+ def empty?
54
+ true
55
+ end
56
+ end
57
+
58
+ class Hash
59
+ def present?
60
+ !blank?
61
+ end
62
+
63
+ def blank?
64
+ empty?
65
+ end
66
+
67
+ def symbolize_keys
68
+ self.inject({}){|rslt, (k, v)| rslt.merge(k.to_sym => v) }
69
+ end
70
+
71
+ def reverse_merge(hash)
72
+ hash.merge self
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module Sentimeta
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/sentimeta.rb CHANGED
@@ -13,5 +13,6 @@ require "sentimeta/client"
13
13
  require "sentimeta/observers"
14
14
  require "sentimeta/model"
15
15
  require "sentimeta/logger"
16
+ require "sentimeta/support"
16
17
  require "sentimeta/railtie" if defined? Rails
17
18
  require "sentimeta/init"
data/sentimeta.gemspec CHANGED
@@ -17,5 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_development_dependency "rake", "~> 10.4"
19
19
  s.add_development_dependency "rspec", "~> 3.1"
20
- s.add_development_dependency "fakeweb", "~> 1.3"
20
+ s.add_development_dependency "webmock", "~> 1.20"
21
+ s.add_development_dependency "vcr", "~> 2.9.3"
22
+
21
23
  end
data/spec/client_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Sentimeta::Client do
3
+ describe Sentimeta::Client, :vcr do
4
4
 
5
5
  subject { Sentimeta::Client }
6
6
 
@@ -13,21 +13,21 @@ describe Sentimeta::Client do
13
13
 
14
14
 
15
15
  describe :generate_uri do
16
- it "should return an instance of URI" do
17
- expect(valid_url).to be_kind_of URI
16
+ it "should return an instance of String" do
17
+ expect(valid_url).to be_kind_of String
18
18
  end
19
19
  end
20
20
 
21
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
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
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
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
31
 
32
32
 
33
33
  describe :endpoints do
@@ -44,9 +44,9 @@ describe Sentimeta::Client do
44
44
  end
45
45
  end
46
46
 
47
- it { should respond_to :prices }
48
- it("#prices should call fetch once") { pending }
49
- it("#prices should return an array") { pending }
47
+ # it { should respond_to :prices }
48
+ # it("#prices should call fetch once") { pending }
49
+ # it("#prices should return an array") { pending }
50
50
  end
51
51
 
52
52
  end
data/spec/model_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Sentimeta::Model do
3
+ describe Sentimeta::Model, :vcr do
4
4
 
5
5
  subject(:client) { Sentimeta::Client }
6
6
  subject { model = Sentimeta::Model; model.endpoint :spheres; model }
data/spec/spec_helper.rb CHANGED
@@ -6,10 +6,13 @@ require 'yaml'
6
6
 
7
7
  Sentimeta.sphere = :hotels
8
8
 
9
- require 'fakeweb'
9
+ require 'webmock/rspec'
10
+ require "vcr"
10
11
 
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}")
12
+ VCR.configure do |config|
13
+ config.cassette_library_dir = "fixtures/vcr_cassettes"
14
+ config.hook_into :webmock
15
+ config.configure_rspec_metadata!
15
16
  end
17
+
18
+
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Shpakov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -67,19 +67,33 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.1'
69
69
  - !ruby/object:Gem::Dependency
70
- name: fakeweb
70
+ name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.3'
75
+ version: '1.20'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.3'
82
+ version: '1.20'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.9.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.9.3
83
97
  description:
84
98
  email: artyom.shpakov@sentimeta.com
85
99
  executables: []
@@ -106,6 +120,7 @@ files:
106
120
  - lib/sentimeta/observers.rb
107
121
  - lib/sentimeta/railtie.rb
108
122
  - lib/sentimeta/rest_client.rb
123
+ - lib/sentimeta/support.rb
109
124
  - lib/sentimeta/version.rb
110
125
  - sentimeta.gemspec
111
126
  - spec/client_spec.rb