rsqoot 0.5.2 → 0.5.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsqoot (0.5.0)
4
+ rsqoot (0.5.3)
5
5
  activesupport (>= 3.0.0)
6
6
  hashie (>= 2.0.0)
7
7
  json (>= 1.6.0)
@@ -9,16 +9,27 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (3.2.13)
13
- i18n (= 0.6.1)
14
- multi_json (~> 1.0)
12
+ activesupport (4.0.3)
13
+ i18n (~> 0.6, >= 0.6.4)
14
+ minitest (~> 4.2)
15
+ multi_json (~> 1.3)
16
+ thread_safe (~> 0.1)
17
+ tzinfo (~> 0.3.37)
18
+ atomic (1.1.14)
15
19
  hashie (2.0.5)
16
- i18n (0.6.1)
20
+ i18n (0.6.9)
17
21
  json (1.8.1)
18
- multi_json (1.8.2)
22
+ minitest (4.7.5)
23
+ multi_json (1.8.4)
24
+ rake (10.1.1)
25
+ thread_safe (0.1.3)
26
+ atomic
27
+ tzinfo (0.3.38)
19
28
 
20
29
  PLATFORMS
21
30
  ruby
22
31
 
23
32
  DEPENDENCIES
33
+ bundler (>= 1.0.0)
34
+ rake
24
35
  rsqoot!
data/README.md CHANGED
@@ -45,56 +45,54 @@ SqootClient.deals(query: 'Home')
45
45
  You can also change your configuration in your own instance, such as below:
46
46
 
47
47
  ```ruby
48
- sqoot ||= RSqoot::Client.new(public_api_key: "YOUR PUBLIC API KEY", private_api_key: 'YOUR PRIVATE API KEY')
48
+ SqootClient.reload!(public_api_key: "YOUR PUBLIC API KEY", private_api_key: 'YOUR PRIVATE API KEY')
49
49
  ```
50
50
 
51
51
  #### Basic Usages
52
52
 
53
53
  ```ruby
54
- sqoot ||= RSqoot::Client.new
55
-
56
- sqoot.deals
54
+ SqootClient.deals
57
55
  #=> returns a list of deals
58
56
 
59
- sqoot.deals(query: 'travel')
57
+ SqootClient.deals(query: 'travel')
60
58
 
61
- sqoot.deals(location: 'Chicago')
59
+ SqootClient.deals(location: 'Chicago')
62
60
 
63
- sqoot.deals(location: 'Chicago', per_page: 10)
61
+ SqootClient.deals(location: 'Chicago', per_page: 10)
64
62
 
65
- sqoot.deals(location: 'Chicago', per_page: 10, categories: 'health-beauty', page: 2)
63
+ SqootClient.deals(location: 'Chicago', per_page: 10, categories: 'health-beauty', page: 2)
66
64
 
67
- sqoot.deals(price_at_least: 10, order: :commission_desc)
65
+ SqootClient.deals(price_at_least: 10, order: :commission_desc)
68
66
 
69
- sqoot.impression(1555288, geometry: '250x250C')
67
+ SqootClient.impression(1555288, geometry: '250x250C')
70
68
  # => return deal_id 1555288's image url which size is 250x250
71
69
 
72
- sqoot.deal(1555288).url
70
+ SqootClient.deal(1555288).url
73
71
  # => return a click url which will redirect to another url
74
72
 
75
- sqoot.providers
73
+ SqootClient.providers
76
74
  # => returns a list of providers
77
75
 
78
- sqoot.providers(query: 'Groupon')
76
+ SqootClient.providers(query: 'Groupon')
79
77
 
80
- sqoot.categories
78
+ SqootClient.categories
81
79
  # => returns a list of categories
82
80
 
83
- sqoot.categories(query: 'home')
84
- sqoot.categories(query: 'home&health')
85
- sqoot.categories(query: 'home,health')
81
+ SqootClient.categories(query: 'home')
82
+ SqootClient.categories(query: 'home&health')
83
+ SqootClient.categories(query: 'home,health')
86
84
 
87
- sqoot.commissions
85
+ SqootClient.commissions
88
86
  # => returns current month commissions
89
87
 
90
- sqoot.commissions(to: '2012-01-01', from: '2012-01-20')
91
- # => returns commissions using date_range :to & :from
88
+ SqootClient.commissions(from: '2012-01-01', to: '2012-01-20')
89
+ # => returns commissions using date_range :from & :to
92
90
 
93
- sqoot.clicks
91
+ SqootClient.clicks
94
92
  # => returns real-time clicks from the event request limit of 1000
95
93
 
96
- sqoot.clicks(to: '2012-01-01', from: '2012-01-20')
97
- # => returns clicks using date_range :to & :from
94
+ SqootClient.clicks(from: '2012-01-01', to: '2012-01-20')
95
+ # => returns clicks using date_range :from & :to
98
96
  ```
99
97
 
100
98
  #### Auto Cache
@@ -104,7 +102,7 @@ Please notice that each query with above methods will automaticlly cache the res
104
102
  If you want to fetch the newest records each time, you can do as below:
105
103
 
106
104
  ```ruby
107
- sqoot.deals(location: 'Chicago', expired_in: 1.second)
105
+ SqootClient.deals(location: 'Chicago', expired_in: 1.second)
108
106
  ```
109
107
 
110
108
  By this, it will update the cache by each query.
@@ -112,13 +110,13 @@ By this, it will update the cache by each query.
112
110
  #### Auto increment for deals
113
111
 
114
112
  ```ruby
115
- sqoot.total_sqoot_deals(query: 'Home', page: 2, category_slugs: 'US')
113
+ SqootClient.total_sqoot_deals(query: 'Home', page: 2, category_slugs: 'US')
116
114
  # For this method, it will cache all the pages for current query options, the more you query the more it will store until reach the end.
117
115
 
118
116
  # For example:
119
- sqoot.total_sqoot_deals(query: 'Home', page: 1, per_page: 20, category_slugs: 'US').count
117
+ SqootClient.total_sqoot_deals(query: 'Home', page: 1, per_page: 20, category_slugs: 'US').count
120
118
  # => 20 records
121
- sqoot.total_sqoot_deals(query: 'Home', page: 2, per_page: 20, category_slugs: 'US').count
119
+ SqootClient.total_sqoot_deals(query: 'Home', page: 2, per_page: 20, category_slugs: 'US').count
122
120
  # => 40 records
123
121
 
124
122
  # But once you change your query options, it will re-cache the records.
data/Rakefile CHANGED
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
@@ -6,5 +6,3 @@ RSqoot.configure do |config|
6
6
  # config.read_timeout = 60.seconds
7
7
  # config.expired_in = 1.hour
8
8
  end
9
-
10
- SqootClient ||= RSqoot::Client.new
data/lib/rsqoot/client.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "singleton"
1
2
  require "rsqoot/helper"
2
3
  require "rsqoot/merchant"
3
4
  require "rsqoot/category"
@@ -10,6 +11,7 @@ require "rsqoot/logger"
10
11
 
11
12
  module RSqoot
12
13
  class Client
14
+ include Singleton
13
15
  include Helper
14
16
  include Category
15
17
  include Click
@@ -20,7 +22,14 @@ module RSqoot
20
22
  include Request
21
23
  include Logger
22
24
 
23
- attr_reader :public_api_key, :private_api_key, :base_api_url, :authentication_method, :read_timeout, :query_options, :expired_in, :sqoot_query_uri
25
+ attr_accessor :public_api_key,
26
+ :private_api_key,
27
+ :base_api_url,
28
+ :authentication_method,
29
+ :read_timeout,
30
+ :query_options,
31
+ :expired_in,
32
+ :sqoot_query_uri
24
33
 
25
34
  def initialize(options={})
26
35
  @public_api_key = options[:public_api_key] || RSqoot.public_api_key
@@ -31,5 +40,9 @@ module RSqoot
31
40
  @expired_in = options[:expired_in] || RSqoot.expired_in
32
41
  end
33
42
 
43
+ def reload!(options={})
44
+ initialize(options)
45
+ self.class.instance
46
+ end
34
47
  end
35
48
  end
data/lib/rsqoot/helper.rb CHANGED
@@ -32,7 +32,7 @@ module RSqoot
32
32
  queries = q.downcase.scan(/[A-Za-z]+|\d+/)
33
33
  if queries.present?
34
34
  queries.map do |q|
35
- instance_variable_get('@rsqoot_'+name).dup.keep_if do |c|
35
+ instance_variable_get('@rsqoot_' + name).dup.keep_if do |c|
36
36
  c.slug =~ Regexp.new(q)
37
37
  end
38
38
  end.flatten.compact.uniq
@@ -42,6 +42,8 @@ module RSqoot
42
42
  end
43
43
 
44
44
  # Add Wrappers: Deal, Category, Commission, Merchant, Provider, Click
45
+ # All records should return as RSqoot::Sqoot* object
46
+ #
45
47
  [ 'SqootDeal',
46
48
  'SqootCategory',
47
49
  'SqootCommission',
data/lib/rsqoot/logger.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  module RSqoot
2
2
  module Logger
3
+
4
+ # Add logger support, easy for log monitor when running your app
5
+ # Output errors and valid records count
6
+ # TODO add color support
7
+ #
3
8
  def logger(options = {records: [], uri: '', error: '', type: '', opts: {}})
4
9
  records = options[:records].nil? ? [] : options[:records]
5
10
  error = options[:error]
@@ -4,6 +4,9 @@ require 'json'
4
4
  module RSqoot
5
5
  module Request
6
6
 
7
+ # Get method, use by all other API qeury methods, fetch records
8
+ # from the Sqoot API V2 url, and provide wrapper functionality
9
+ #
7
10
  def get(path, opts = {}, wrapper = ::Hashie::Mash)
8
11
  uri, headers = url_generator(path, opts)
9
12
  begin
@@ -17,6 +20,9 @@ module RSqoot
17
20
  end
18
21
  end
19
22
 
23
+ # Generate valid Sqoot API V2 url and provide two different way of
24
+ # authentication: :header, :parameter
25
+ #
20
26
  def url_generator(path, opts = {}, require_key = false)
21
27
  uri = URI.parse base_api_url
22
28
  headers = {read_timeout: read_timeout}
@@ -37,14 +43,19 @@ module RSqoot
37
43
 
38
44
  private
39
45
 
46
+ # Endpoints that needs private key
47
+ #
40
48
  def private_endpoints
41
49
  %w(clicks commissions)
42
50
  end
43
51
 
52
+ # Endpoints that both public or private key will work
53
+ #
44
54
  def public_endpoints
45
55
  %w(categories deals merchants providers)
46
56
  end
47
57
 
58
+ # Decide which api key should be used: private, public
48
59
  def api_key(endpoint='')
49
60
  if private_endpoints.include? endpoint
50
61
  private_api_key
@@ -1,3 +1,3 @@
1
1
  module RSqoot
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
data/lib/rsqoot.rb CHANGED
@@ -15,6 +15,7 @@ module RSqoot
15
15
  raise "You must add your own public api key to initializer ." if self.public_api_key.nil?
16
16
  raise "You must add your own private api key to initializer ." if self.private_api_key.nil?
17
17
  raise "Authentication method must be :header or :parameter ." if !AUTHENTICATION_METHODS.include? self.authentication_method
18
+ SqootClient.reload!
18
19
  true
19
20
  end
20
21
 
@@ -32,3 +33,10 @@ module RSqoot
32
33
  end
33
34
 
34
35
  end
36
+
37
+ begin
38
+ RSqoot.load_defaults
39
+ SqootClient ||= RSqoot::Client.instance
40
+ rescue => e
41
+ raise e
42
+ end
data/rsqoot.gemspec CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "json", ">= 1.6.0"
23
23
  s.add_dependency "activesupport", ">= 3.0.0"
24
24
 
25
+ s.add_development_dependency 'bundler', ['>= 1.0.0']
26
+ s.add_development_dependency 'rake', ['>= 0']
27
+
25
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsqoot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-18 00:00:00.000000000 Z
12
+ date: 2014-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
62
94
  description: A Ruby Wrapper for Sqoot API V2.
63
95
  email:
64
96
  - lyfeyaj@gmail.com
@@ -101,12 +133,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
133
  - - ! '>='
102
134
  - !ruby/object:Gem::Version
103
135
  version: '0'
136
+ segments:
137
+ - 0
138
+ hash: 309329620517368495
104
139
  required_rubygems_version: !ruby/object:Gem::Requirement
105
140
  none: false
106
141
  requirements:
107
142
  - - ! '>='
108
143
  - !ruby/object:Gem::Version
109
144
  version: '0'
145
+ segments:
146
+ - 0
147
+ hash: 309329620517368495
110
148
  requirements: []
111
149
  rubyforge_project:
112
150
  rubygems_version: 1.8.26