getclicky 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +84 -0
- data/getclicky.gemspec +2 -1
- data/lib/getclicky.rb +5 -0
- data/lib/getclicky/client.rb +6 -0
- data/lib/getclicky/request.rb +2 -2
- data/lib/getclicky/response.rb +36 -4
- data/lib/getclicky/version.rb +1 -1
- data/spec/getclicky/request_spec.rb +12 -3
- data/spec/getclicky/response_spec.rb +36 -0
- data/spec/getclicky_spec.rb +7 -2
- data/spec/spec_helper.rb +9 -3
- data/spec/support/helpers.rb +2 -4
- metadata +28 -15
- data/README.rdoc +0 -79
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Getclicky API Analytics Library
|
2
|
+
|
3
|
+
A swiss knife ruby wrapper for Getclicky API Analytics. For more information see: http://getclicky.com/help/api.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
## Gemfile for Rails 3, Sinatra, and Merb
|
9
|
+
gem 'getclicky', '~> 0.1'
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Ruby wrapper
|
15
|
+
|
16
|
+
First, you'll need to set up your site_id and sitekey. You can discover this information by accessing settings in your account at http://getclicky.com.
|
17
|
+
|
18
|
+
``` ruby
|
19
|
+
Getclicky.configure do |config|
|
20
|
+
config.site_id = "your site id here"
|
21
|
+
config.sitekey = "your site key here"
|
22
|
+
config.admin_sitekey = "your admin site key, if applicable"
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Then you can simply instantiate a new Getclicky::Client object.
|
27
|
+
|
28
|
+
``` ruby
|
29
|
+
getclicky = Getclicky::Client.new
|
30
|
+
```
|
31
|
+
|
32
|
+
All types in API are methods here looks, you can find all types http://getclicky.com/help/api:
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
getclicky.pages()
|
36
|
+
getclicky.tweets()
|
37
|
+
getclicky.visitors()
|
38
|
+
```
|
39
|
+
|
40
|
+
In each method you can pass optional parameters as a hash looks:
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
getclicky.visitors(:date => "last-7-days", :daily => 1)
|
44
|
+
getclicky.item(:date => "last-7-days", :item => "google.com")
|
45
|
+
getclicky.visitors_list(:domain => "google.com")
|
46
|
+
```
|
47
|
+
|
48
|
+
You can also request more than one data type in a single request:
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
getclicky.multiple([:pages, :downloads], {:date => "last-7-days"})
|
52
|
+
```
|
53
|
+
|
54
|
+
By default getclicky API returns an array of [Hashies](https://github.com/intridea/hashie) as data, but you can change by providing an :output parameter like:
|
55
|
+
|
56
|
+
##### JSON
|
57
|
+
|
58
|
+
``` ruby
|
59
|
+
getclicky.visitors(:output => :json, :date => "last-7-days", :daily => 1)
|
60
|
+
```
|
61
|
+
|
62
|
+
##### CSV
|
63
|
+
|
64
|
+
``` ruby
|
65
|
+
getclicky.visitors(:output => :csv, :date => "last-7-days", :daily => 1)
|
66
|
+
```
|
67
|
+
|
68
|
+
##### PHP
|
69
|
+
|
70
|
+
``` ruby
|
71
|
+
getclicky.visitors(:output => :php, :date => "last-7-days", :daily => 1)
|
72
|
+
```
|
73
|
+
|
74
|
+
Enjoy!
|
75
|
+
|
76
|
+
## Roadmap
|
77
|
+
|
78
|
+
* Improve the tests
|
79
|
+
|
80
|
+
## Author
|
81
|
+
* Peterson Ferreira ([refactoringever.com](refactoringever.com))
|
82
|
+
|
83
|
+
## Collaborators
|
84
|
+
* Bobby Uhlenbrock ([github.com/uhlenbrock](github.com/uhlenbrock))
|
data/getclicky.gemspec
CHANGED
@@ -11,7 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.summary = %q{Ruby Wrapper for GetClicky API Analytics}
|
12
12
|
s.description = s.summary
|
13
13
|
|
14
|
-
s.add_dependency "httparty" , "~> 0.
|
14
|
+
s.add_dependency "httparty" , "~> 0.8.0"
|
15
|
+
s.add_dependency "hashie" , "~> 1.1.0"
|
15
16
|
s.add_development_dependency "rspec" , "~> 2.6"
|
16
17
|
s.add_development_dependency "test_notifier", "~> 0.3"
|
17
18
|
s.add_development_dependency "fakeweb" , "~> 1.3"
|
data/lib/getclicky.rb
CHANGED
data/lib/getclicky/client.rb
CHANGED
@@ -11,5 +11,11 @@ module Getclicky
|
|
11
11
|
end # end
|
12
12
|
RUBY
|
13
13
|
end
|
14
|
+
|
15
|
+
def multiple(types = [], params = {})
|
16
|
+
valid_types = types.reject { |t| !Getclicky::Types::ALL.include?(t.intern) }
|
17
|
+
response = Getclicky::Request.new(valid_types.join(','), params).get
|
18
|
+
response.data
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/getclicky/request.rb
CHANGED
@@ -18,14 +18,14 @@ module Getclicky
|
|
18
18
|
when "404"
|
19
19
|
raise Getclicky::NotFoundError
|
20
20
|
else
|
21
|
-
Getclicky::Response.new(response)
|
21
|
+
Getclicky::Response.new(response.parsed_response, @params[:output])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
# Build the hash of options for make resquest to API
|
26
26
|
#
|
27
27
|
def build_params(type, params = {})
|
28
|
-
query = { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => type }
|
28
|
+
query = { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => type, :output => :json }
|
29
29
|
query.merge(params) if params
|
30
30
|
end
|
31
31
|
end
|
data/lib/getclicky/response.rb
CHANGED
@@ -1,13 +1,45 @@
|
|
1
|
+
require "hashie"
|
2
|
+
|
1
3
|
module Getclicky
|
2
|
-
class Response
|
3
|
-
attr_accessor :item
|
4
|
+
class Response
|
5
|
+
attr_accessor :item, :format
|
4
6
|
|
5
|
-
|
7
|
+
class << self
|
8
|
+
attr_accessor :mash_class
|
9
|
+
end
|
10
|
+
|
11
|
+
self.mash_class = ::Hashie::Mash
|
12
|
+
|
13
|
+
def initialize(item, format = nil)
|
6
14
|
@item = item
|
15
|
+
@format = format
|
7
16
|
end
|
8
17
|
|
9
18
|
def data
|
10
|
-
@item
|
19
|
+
@format.nil? ? mashify_data : @item
|
20
|
+
end
|
21
|
+
|
22
|
+
def mashify_data
|
23
|
+
if @item.size.eql?(1)
|
24
|
+
parse(@item.first['dates'])
|
25
|
+
elsif @item.size > 1
|
26
|
+
{}.tap do |results|
|
27
|
+
@item.collect { |r| results[r['type'].intern] = parse(r['dates']) }
|
28
|
+
end
|
29
|
+
else
|
30
|
+
@item
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse(body)
|
35
|
+
case body
|
36
|
+
when Hash
|
37
|
+
self.class.mash_class.new(body)
|
38
|
+
when Array
|
39
|
+
body.map { |item| item.is_a?(Hash) ? self.class.mash_class.new(item) : item }
|
40
|
+
else
|
41
|
+
body
|
42
|
+
end
|
11
43
|
end
|
12
44
|
end
|
13
45
|
end
|
data/lib/getclicky/version.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Getclicky::Request do
|
4
|
-
|
5
4
|
subject {
|
6
5
|
Getclicky::Request.new(:pages, :limit => 10, :hourly => 1)
|
7
6
|
}
|
@@ -12,12 +11,22 @@ describe Getclicky::Request do
|
|
12
11
|
context "method build_params" do
|
13
12
|
it "should be set the right parameters" do
|
14
13
|
params = subject.build_params(:pages, :limit => 10, :hourly => 1)
|
15
|
-
params.should == { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => :pages, :limit => 10, :hourly => 1}
|
14
|
+
params.should == { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => :pages, :limit => 10, :hourly => 1, :output => :json}
|
16
15
|
end
|
17
16
|
|
18
17
|
it "should be leave hash parameters blank" do
|
19
18
|
params = subject.build_params(:pages)
|
20
|
-
params.should == { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => :pages}
|
19
|
+
params.should == { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => :pages, :output => :json}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should default to an output format of json" do
|
23
|
+
params = subject.build_params(:pages)
|
24
|
+
params.should == { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => :pages, :output => :json}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow overriding the output format" do
|
28
|
+
params = subject.build_params(:pages, :output => :xml)
|
29
|
+
params.should == { :site_id => Getclicky.site_id, :sitekey => Getclicky.sitekey, :type => :pages, :output => :xml}
|
21
30
|
end
|
22
31
|
end
|
23
32
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Getclicky::Response do
|
4
|
+
subject {
|
5
|
+
Getclicky::Response.new([{
|
6
|
+
"type"=>"pages",
|
7
|
+
"dates"=>
|
8
|
+
[{"date"=>"2011-09-27",
|
9
|
+
"items"=>
|
10
|
+
[{"value"=>"6",
|
11
|
+
"value_percent"=>"66.7",
|
12
|
+
"title"=>"Test Page",
|
13
|
+
"stats_url"=>"http://getclicky.com/stats/visitors",
|
14
|
+
"url"=>"http://blackbookemg.dev/posts"},
|
15
|
+
{"value"=>"1",
|
16
|
+
"value_percent"=>"11.1",
|
17
|
+
"title"=>"Test Page 2",
|
18
|
+
"stats_url"=>
|
19
|
+
"http://getclicky.com/stats/visitors",
|
20
|
+
"url"=>"http://blackbookemg.dev/requests/1"}
|
21
|
+
]}
|
22
|
+
]
|
23
|
+
}])
|
24
|
+
}
|
25
|
+
|
26
|
+
its(:item) { should be_an_instance_of Array }
|
27
|
+
its(:data) { should be_an_instance_of Array }
|
28
|
+
|
29
|
+
context "when using" do
|
30
|
+
it "should return an array of Hashie objects" do
|
31
|
+
subject.data.each do |d|
|
32
|
+
d.should be_an_instance_of Hashie::Mash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/getclicky_spec.rb
CHANGED
@@ -11,6 +11,11 @@ describe Getclicky do
|
|
11
11
|
Getclicky.configure { |c| c.sitekey = "123" }
|
12
12
|
Getclicky.sitekey.should == "123"
|
13
13
|
end
|
14
|
+
|
15
|
+
it "should be set admin_sitekey" do
|
16
|
+
Getclicky.configure { |c| c.admin_sitekey = "123" }
|
17
|
+
Getclicky.admin_sitekey.should == "123"
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
describe "endpoint" do
|
@@ -20,8 +25,8 @@ describe Getclicky do
|
|
20
25
|
end
|
21
26
|
|
22
27
|
it "should be changes the url" do
|
23
|
-
ENV["GETCLICKY_ENDPOINT"] = "http://getclicky.com"
|
24
|
-
Getclicky.endpoint.should == "http://getclicky.com"
|
28
|
+
ENV["GETCLICKY_ENDPOINT"] = "http://api.getclicky.com/api/stats/4"
|
29
|
+
Getclicky.endpoint.should == "http://api.getclicky.com/api/stats/4"
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,13 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|file| require file}
|
|
13
13
|
RSpec.configure do |config|
|
14
14
|
config.include Helpers
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
config.before do
|
17
|
+
ENV.delete("GETCLICKY_ENDPOINT")
|
18
|
+
end
|
19
|
+
|
20
|
+
Getclicky.configure do |config|
|
21
|
+
config.site_id = nil
|
22
|
+
config.sitekey = nil
|
23
|
+
config.admin_sitekey = nil
|
24
|
+
end
|
19
25
|
end
|
data/spec/support/helpers.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getclicky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-09-30 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &70195420885440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.8.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70195420885440
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hashie
|
27
|
+
requirement: &70195420884800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70195420884800
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rspec
|
27
|
-
requirement: &
|
38
|
+
requirement: &70195420884180 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ~>
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '2.6'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70195420884180
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: test_notifier
|
38
|
-
requirement: &
|
49
|
+
requirement: &70195420880680 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ~>
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0.3'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70195420880680
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: fakeweb
|
49
|
-
requirement: &
|
60
|
+
requirement: &70195420879980 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ~>
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '1.3'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70195420879980
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: ruby-debug19
|
60
|
-
requirement: &
|
71
|
+
requirement: &70195420879480 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ~>
|
@@ -65,7 +76,7 @@ dependencies:
|
|
65
76
|
version: '0.11'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70195420879480
|
69
80
|
description: Ruby Wrapper for GetClicky API Analytics
|
70
81
|
email:
|
71
82
|
- petersonferreiras@gmail.com
|
@@ -76,7 +87,7 @@ files:
|
|
76
87
|
- .gitignore
|
77
88
|
- Gemfile
|
78
89
|
- LICENSE
|
79
|
-
- README.
|
90
|
+
- README.md
|
80
91
|
- Rakefile
|
81
92
|
- getclicky.gemspec
|
82
93
|
- lib/getclicky.rb
|
@@ -87,6 +98,7 @@ files:
|
|
87
98
|
- lib/getclicky/version.rb
|
88
99
|
- spec/getclicky/client_spec.rb
|
89
100
|
- spec/getclicky/request_spec.rb
|
101
|
+
- spec/getclicky/response_spec.rb
|
90
102
|
- spec/getclicky_spec.rb
|
91
103
|
- spec/spec_helper.rb
|
92
104
|
- spec/support/helpers.rb
|
@@ -110,13 +122,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
122
|
version: '0'
|
111
123
|
requirements: []
|
112
124
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
125
|
+
rubygems_version: 1.8.9
|
114
126
|
signing_key:
|
115
127
|
specification_version: 3
|
116
128
|
summary: Ruby Wrapper for GetClicky API Analytics
|
117
129
|
test_files:
|
118
130
|
- spec/getclicky/client_spec.rb
|
119
131
|
- spec/getclicky/request_spec.rb
|
132
|
+
- spec/getclicky/response_spec.rb
|
120
133
|
- spec/getclicky_spec.rb
|
121
134
|
- spec/spec_helper.rb
|
122
135
|
- spec/support/helpers.rb
|
data/README.rdoc
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# Getclicky API Analytics Library
|
2
|
-
|
3
|
-
A swiss knife ruby wrapper for Getclicky API Analytics. For more information see: http://getclicky.com/help/api.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
``` ruby
|
8
|
-
## Gemfile for Rails 3, Sinatra, and Merb
|
9
|
-
gem 'will_paginate', '~> 3.0'
|
10
|
-
```
|
11
|
-
|
12
|
-
|
13
|
-
## Usage
|
14
|
-
|
15
|
-
### Ruby wrapper
|
16
|
-
|
17
|
-
First, you'll need to set up your site_id and sitekey. You can discover this information by accessing settings in your account at http://getclicky.com.
|
18
|
-
|
19
|
-
``` ruby
|
20
|
-
Getclicky.configure do |config|
|
21
|
-
config.site_id = "your site id here"
|
22
|
-
config.sitekey = "your site key here"
|
23
|
-
end
|
24
|
-
```
|
25
|
-
|
26
|
-
Then you can simply instantiate a new Getclicky::Client object.
|
27
|
-
|
28
|
-
``` ruby
|
29
|
-
getclicky = Getclicky::Client.new
|
30
|
-
```
|
31
|
-
|
32
|
-
### Usage
|
33
|
-
|
34
|
-
All types in API are methods here looks, you can find all types http://getclicky.com/help/api:
|
35
|
-
|
36
|
-
``` ruby
|
37
|
-
getClicky.pages()
|
38
|
-
getClicky.tweets()
|
39
|
-
getClicky.visitors()
|
40
|
-
```
|
41
|
-
|
42
|
-
In each method you can pass optional parameters as a hash looks:
|
43
|
-
|
44
|
-
``` ruby
|
45
|
-
getClicky.visitors(:date => "last-7-days", :daily => 1)
|
46
|
-
getClicky.item(:date => "last-7-days", :item => "google.com")
|
47
|
-
getClicky.visitors_list(:domain => "google.com")
|
48
|
-
```
|
49
|
-
|
50
|
-
By default getclicky API returns XML as data, but you can change adding :output in parameter like:
|
51
|
-
|
52
|
-
##### JSON
|
53
|
-
|
54
|
-
``` ruby
|
55
|
-
getClicky.visitors(:output => :json, :date => "last-7-days", :daily => 1)
|
56
|
-
```
|
57
|
-
|
58
|
-
##### CSV
|
59
|
-
|
60
|
-
``` ruby
|
61
|
-
getClicky.visitors(:output => :csv, :date => "last-7-days", :daily => 1)
|
62
|
-
```
|
63
|
-
|
64
|
-
##### PHP
|
65
|
-
|
66
|
-
``` ruby
|
67
|
-
getClicky.visitors(:output => :php, :date => "last-7-days", :daily => 1)
|
68
|
-
```
|
69
|
-
|
70
|
-
This library does't support multiple types yet.
|
71
|
-
|
72
|
-
## Roadmap
|
73
|
-
|
74
|
-
* Multiple types for request
|
75
|
-
* Improve the tests
|
76
|
-
|
77
|
-
## Maintainer
|
78
|
-
|
79
|
-
* Peterson Ferreira (petersonferreiras@gmail.com)
|