shared_count_api 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c296f7db9d808d5a5ca56f2e65ef1c3c982a020a
4
- data.tar.gz: 13a35672bdee8df4aad645357ebe1e2494ab41a1
3
+ metadata.gz: b4138b75b31c0c1e3b2dd6cfb0ad3e7f9dbbf9e1
4
+ data.tar.gz: 3b625891db51b88d2a857924e58974fdaa35dcee
5
5
  SHA512:
6
- metadata.gz: 8e400c6453447b54f0653887acd6c5bce1eaeb7f8f4d85f8266fb90f7fc05b97b477e7ad75a89dc400ebf835eee22e0df3c93e74bdca6484d509dedba7a97f72
7
- data.tar.gz: 367c36c0cfe875c0c18cb68f09cd7067ed2a45bad3acbb26f15d0df539fa5e07b63775c5daad1736498acaf4ecc74dbad0ddc99fda30d908d8b6e9ac8c98be93
6
+ metadata.gz: 83d078a5b1451bf937afe4bad7536fa16bc1de005c96a3304528caf60d1f8772f9f4f5aa6b793eae9f795c14bf71a47bdf3a2360d56cd015dc361bb1aff072c1
7
+ data.tar.gz: f90bf5656d3d68df23a7ebe91cbee86f05be17e028d5592ff73593bfd2bbfac82f3d1020f388d9e35daedd139badffebc922433d1812dcce01493e8dff426beb
data/README.md CHANGED
@@ -20,6 +20,12 @@ Or install it yourself as:
20
20
 
21
21
  ```ruby
22
22
  require "shared_count_api"
23
+
24
+ SharedCountApi.configure do |config|
25
+ config.apikey = 'my-api-key'
26
+ config.url = 'my-dedicated-url' # only use if you have a dedicated url plan
27
+ end
28
+
23
29
  client = SharedCountApi::Client.new("http://slashdot.org")
24
30
  client.twitter # => 24381
25
31
  client.facebook_share_count # => 2705
@@ -12,6 +12,26 @@ module SharedCountApi
12
12
  end
13
13
  end
14
14
 
15
+ class << self
16
+ attr_accessor :apikey, :url
17
+
18
+ # config/initializers/shared_count_api.rb (for instance)
19
+ #
20
+ # SharedCountApi.configure do |config|
21
+ # config.apikey = 'my-api-key'
22
+ # config.url = 'my-dedicated-url' # only use if you have a dedicated url plan
23
+ # end
24
+ #
25
+ # elsewhere
26
+ #
27
+ # client = SharedCountApi::Client.new
28
+ def configure
29
+ yield self
30
+ true
31
+ end
32
+
33
+ end
34
+
15
35
  INVALID_URL = Error.new("invalid_url", "Not a valid URL.")
16
36
 
17
37
  class Client
@@ -19,7 +39,13 @@ module SharedCountApi
19
39
  HTTPS_ENDPOINT = "https://sharedcount.appspot.com/".freeze
20
40
 
21
41
  def initialize(url, use_ssl = false)
22
- @url, @use_ssl = url, use_ssl
42
+ @url, @use_ssl = URI.escape(url), use_ssl
43
+
44
+ if SharedCountApi.url
45
+ @endpoint = SharedCountApi.url
46
+ else
47
+ @endpoint = @use_ssl ? HTTPS_ENDPOINT : HTTP_ENDPOINT
48
+ end
23
49
  end
24
50
 
25
51
  def stumble_upon
@@ -66,17 +92,15 @@ module SharedCountApi
66
92
  response["LinkedIn"]
67
93
  end
68
94
 
69
- private
70
-
71
- def facebook_metrics
72
- @facebook_metrics ||= response["Facebook"].is_a?(Hash) ? response["Facebook"] : Hash.new(0)
73
- end
74
-
75
95
  def response
76
96
  @response ||= begin
77
- endpoint = @use_ssl ? HTTPS_ENDPOINT : HTTP_ENDPOINT
78
97
  begin
79
- uri = URI("#{endpoint}?url=#{@url}")
98
+ uri = if SharedCountApi.apikey
99
+ URI("#{@endpoint}?url=#{@url}&apikey=#{SharedCountApi.apikey}")
100
+ else
101
+ URI("#{@endpoint}?url=#{@url}")
102
+ end
103
+
80
104
  res = Net::HTTP.get_response(uri)
81
105
 
82
106
  case res
@@ -91,5 +115,11 @@ module SharedCountApi
91
115
  end
92
116
  end
93
117
  end
118
+
119
+ private
120
+
121
+ def facebook_metrics
122
+ @facebook_metrics ||= response["Facebook"].is_a?(Hash) ? response["Facebook"] : Hash.new(0)
123
+ end
94
124
  end
95
125
  end
@@ -1,3 +1,3 @@
1
1
  module SharedCountApi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -113,6 +113,10 @@ describe SharedCountApi::Client do
113
113
  it "includes the number of LinkedIn shares" do
114
114
  subject.linked_in.must_equal body[:LinkedIn]
115
115
  end
116
+
117
+ it "exposes the entire response hash" do
118
+ subject.response.must_be_instance_of Hash
119
+ end
116
120
  end
117
121
  end
118
122
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shared_count_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristian Rasch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-03 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.0.3
92
+ rubygems_version: 2.0.14
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: This library wraps the SharedCount API exposing its data through POROs (Plain