twelve 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE +21 -0
  4. data/README.md +220 -0
  5. data/Rakefile +8 -0
  6. data/lib/twelve.rb +32 -0
  7. data/lib/twelve/api/clients.rb +55 -0
  8. data/lib/twelve/api/gauges.rb +67 -0
  9. data/lib/twelve/api/gauges/content.rb +36 -0
  10. data/lib/twelve/api/gauges/engines.rb +32 -0
  11. data/lib/twelve/api/gauges/locations.rb +32 -0
  12. data/lib/twelve/api/gauges/referrers.rb +36 -0
  13. data/lib/twelve/api/gauges/resolutions.rb +32 -0
  14. data/lib/twelve/api/gauges/shares.rb +45 -0
  15. data/lib/twelve/api/gauges/technology.rb +32 -0
  16. data/lib/twelve/api/gauges/terms.rb +36 -0
  17. data/lib/twelve/api/gauges/traffic.rb +32 -0
  18. data/lib/twelve/api/me.rb +28 -0
  19. data/lib/twelve/connection.rb +26 -0
  20. data/lib/twelve/resource_proxy.rb +46 -0
  21. data/lib/twelve/version.rb +4 -0
  22. data/spec/spec_helper.rb +17 -0
  23. data/spec/twelve/api/clients_spec.rb +43 -0
  24. data/spec/twelve/api/gauges/content_spec.rb +54 -0
  25. data/spec/twelve/api/gauges/engines_spec.rb +32 -0
  26. data/spec/twelve/api/gauges/locations_spec.rb +32 -0
  27. data/spec/twelve/api/gauges/referrers_spec.rb +54 -0
  28. data/spec/twelve/api/gauges/resolutions_spec.rb +36 -0
  29. data/spec/twelve/api/gauges/shares_spec.rb +74 -0
  30. data/spec/twelve/api/gauges/technology_spec.rb +36 -0
  31. data/spec/twelve/api/gauges/terms_spec.rb +52 -0
  32. data/spec/twelve/api/gauges/traffic_spec.rb +34 -0
  33. data/spec/twelve/api/gauges_spec.rb +119 -0
  34. data/spec/twelve/api/me_spec.rb +34 -0
  35. data/spec/twelve/connection_spec.rb +11 -0
  36. data/spec/twelve/resource_proxy_spec.rb +34 -0
  37. data/spec/twelve_spec.rb +16 -0
  38. data/twelve.gemspec +29 -0
  39. metadata +230 -0
@@ -0,0 +1,5 @@
1
+ README (Autosaved)
2
+ Gemfile.lock
3
+ spec/.access_token
4
+ spec/responses/
5
+ spec/.gauge_id
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Jonathan Hoyt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,220 @@
1
+ Twelve (gauge)
2
+ ==================
3
+
4
+ This is an unofficial ruby client for the [Gauges API](http://get.gaug.es/documentation/api/). The end goal is a complete, simple, and intuitive ruby API for all things Gauges.
5
+
6
+ Usage
7
+ -----
8
+
9
+ Instantiate the client:
10
+
11
+ access_token = "abcd1234"
12
+ bfg = Twelve.new(access_token)
13
+
14
+ ### Your Information
15
+
16
+ Get your information:
17
+
18
+ bfg.me
19
+
20
+ Update your information:
21
+
22
+ bfg.me({
23
+ :first_name => "John",
24
+ :last_name => "Doe"
25
+ })
26
+
27
+ ### API Clients
28
+
29
+ Get your API clients:
30
+
31
+ bfg.clients
32
+
33
+ Create an API client:
34
+
35
+ bfg.clients.create(:description => "12 Gauge")
36
+
37
+ Delete an API client:
38
+
39
+ client_id = 'abcd1234'
40
+ bfg.clients(client_id).destroy
41
+
42
+ ### Gauges
43
+
44
+ Get your gauges:
45
+
46
+ bfg.gauges
47
+
48
+ Create a gauge:
49
+
50
+ bfg.gauges.create({
51
+ :title => 'theprogrammingbutler.com',
52
+ :tz => 'Eastern Time (US & Canada)'
53
+ })
54
+
55
+ Get a specific gauge:
56
+
57
+ gauge_id = 'abcd1234'
58
+ bfg.gauges(gauge_id)
59
+
60
+ Update a gauge:
61
+
62
+ bfg.gauges('abcd1234', {
63
+ :title => 'Go get your guns'
64
+ })
65
+
66
+ Delete a gauge:
67
+
68
+ bfg.gauges('abcd1234').destroy
69
+
70
+ ### Sharing
71
+
72
+ List who a gauge is shared with:
73
+
74
+ bfg.gauges('abcd1234').shares
75
+
76
+ Share a gauge:
77
+
78
+ bfg.gauges('abcd1234').share({:email => 'john@doe.com'})
79
+
80
+ Un-share a gauge:
81
+
82
+ user_id = '4321dcba'
83
+ bfg.gauges('abcd1234').unshare(user_id)
84
+
85
+ ### Content
86
+
87
+ Get today's top content for a gauge:
88
+
89
+ bfg.gauges('abcd1234').content
90
+
91
+ Get the second page of top content for a gauge:
92
+
93
+ bfg.gauges('abcd1234').content(:page => 2)
94
+
95
+ Get top content for a specific date of a gauge:
96
+
97
+ bfg.gauges('abcd1234').content('2011-12-9')
98
+
99
+ Get the second page for a specific date:
100
+
101
+ bfg.gauges('abcd1234').content('2011-12-9', :page => 2)
102
+
103
+ ### Referrers
104
+
105
+ Get today's referrers for a gauge:
106
+
107
+ bfg.gauges('abcd1234').referrers
108
+
109
+ Get the second page of referrers for a gauge:
110
+
111
+ bfg.gauges('abcd1234').referrers(:page => 2)
112
+
113
+ Get referrers for a specific date of a gauge:
114
+
115
+ bfg.gauges('abcd1234').referrers('2011-12-9')
116
+
117
+ Get the second page for a specific date:
118
+
119
+ bfg.gauges('abcd1234').referrers('2011-12-9', :page => 2)
120
+
121
+ ### Trafic
122
+
123
+ Get this month's traffic for a gauge:
124
+
125
+ bfg.gauges('abcd1234').traffic
126
+
127
+ Get a specific month's traffic:
128
+
129
+ bfg.gauges('abcd1234').traffic('2011-10-1')
130
+
131
+ ### Resolutions
132
+
133
+ Get this month's screen sizes for a gauge:
134
+
135
+ bfg.gauges('abcd1234').traffic
136
+
137
+ Get a specific month's screen sizes:
138
+
139
+ bfg.gauges('abcd1234').traffic('2011-10-1')
140
+
141
+ ### Technology
142
+
143
+ Get browsers and platforms for a gauge:
144
+
145
+ bfg.gauges('abcd1234').technology
146
+
147
+ Get a specific month's technology:
148
+
149
+ bfg.gauges('abcd1234').technology('2011-10-1')
150
+
151
+ ### Search Terms
152
+
153
+ Get today's search terms for a gauge:
154
+
155
+ bfg.gauges('abcd1234').terms
156
+
157
+ Get the second page of search terms for a gauge:
158
+
159
+ bfg.gauges('abcd1234').terms(:page => 2)
160
+
161
+ Get search terms for a specific date of a gauge:
162
+
163
+ bfg.gauges('abcd1234').terms('2011-12-9')
164
+
165
+ Get the second page for a specific date:
166
+
167
+ bfg.gauges('abcd1234').terms('2011-12-9', :page => 2)
168
+
169
+ ### Search Engines
170
+
171
+ Get search engines for a gauge:
172
+
173
+ bfg.gauges('abcd1234').engines
174
+
175
+ Get a specific month's search engines:
176
+
177
+ bfg.gauges('abcd1234').engines('2011-10-1')
178
+
179
+ ### Locations
180
+
181
+ Get this month's locations for a gauge:
182
+
183
+ bfg.gauges('abcd1234').locations
184
+
185
+ Get a specific month's locations:
186
+
187
+ bfg.gauges('abcd1234').locations('2011-10-1')
188
+
189
+ Testing
190
+ -------
191
+
192
+ The test suite uses [VCR](https://github.com/myronmarston/vcr) to cache actual requests to the Gauges API in a directory called responses in the spec directory. In order for VCR to make and cache the actual calls to the Gauges API you will need to provide your Gauges access_token by placing it in a file named .access_token in the spec directory.
193
+
194
+ To run the tests for content, referrers, traffic, resolutions, technology, search terms, search engines, and locations, you will also need to have an id for a gauge that has been collecting data for at least two days. You place this gauge id in spec/.gauge_id and spec_helper will use it.
195
+
196
+ This file is ignored by git (see .gitignore) so you can commit any changes you make to the gem without having to worry about your token being released into the wild.
197
+
198
+ Now run the test suite:
199
+
200
+ bundle
201
+ bundle exec rake
202
+
203
+ CONTRIBUTE
204
+ ----------
205
+
206
+ If you'd like to hack on Twelve, start by forking the repo on GitHub:
207
+
208
+ https://github.com/jonmagic/twelve
209
+
210
+ The best way to get your changes merged back into core is as follows:
211
+
212
+ 1. Clone down your fork
213
+ 1. Create a thoughtfully named topic branch to contain your change
214
+ 1. Hack away
215
+ 1. Add tests and make sure everything still passes by running `bundle exec rake`
216
+ 1. If you are adding new functionality, document it in the README
217
+ 1. Do not change the version number, we will do that on our end
218
+ 1. If necessary, rebase your commits into logical chunks, without errors
219
+ 1. Push the branch up to GitHub
220
+ 1. Send a pull request for your branch
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ desc "Run the specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ require 'twelve/version'
3
+ require 'twelve/connection'
4
+ require 'twelve/resource_proxy'
5
+ require 'twelve/api/me'
6
+ require 'twelve/api/clients'
7
+ require 'twelve/api/gauges/shares'
8
+ require 'twelve/api/gauges/content'
9
+ require 'twelve/api/gauges/referrers'
10
+ require 'twelve/api/gauges/traffic'
11
+ require 'twelve/api/gauges/resolutions'
12
+ require 'twelve/api/gauges/technology'
13
+ require 'twelve/api/gauges/terms'
14
+ require 'twelve/api/gauges/engines'
15
+ require 'twelve/api/gauges/locations'
16
+ require 'twelve/api/gauges'
17
+
18
+ class Twelve
19
+ attr_reader :connection
20
+
21
+ include Twelve::API::Me
22
+ include Twelve::API::Clients
23
+ include Twelve::API::Gauges
24
+
25
+ # Instantiates Twelve, requires an access_token
26
+ #
27
+ # Access_token - String of the access_token
28
+ #
29
+ def initialize(access_token=nil)
30
+ @connection = Twelve::Connection.new(access_token)
31
+ end
32
+ end
@@ -0,0 +1,55 @@
1
+ class Twelve
2
+
3
+ # API module encapsulates all of the API endpoints
4
+ #
5
+ module API
6
+
7
+ # The Clients module handles API Clients on Gauges
8
+ #
9
+ module Clients
10
+
11
+ # Clients::Proxy inherits from Twelve::Proxy and
12
+ # enables defining methods on the proxy object
13
+ #
14
+ class Proxy < ::Twelve::ResourceProxy
15
+
16
+ # Creates an API client
17
+ #
18
+ # attributes - Hash of attributes
19
+ #
20
+ # Returns json
21
+ #
22
+ def create(attributes)
23
+ connection.post(path_prefix, attributes).body['client']
24
+ end
25
+
26
+ # Deletes an API client
27
+ #
28
+ # key - String of key
29
+ #
30
+ # Returns json
31
+ #
32
+ def destroy
33
+ connection.delete(path_prefix).body['client']
34
+ end
35
+
36
+ # Get API clients
37
+ #
38
+ # Returns json
39
+ #
40
+ def subject
41
+ @subject ||= connection.get(path_prefix).body['clients']
42
+ end
43
+ end
44
+
45
+ # Get API clients
46
+ #
47
+ # Returns json
48
+ #
49
+ def clients(id=nil)
50
+ path_prefix = id ? "/clients/#{id}" : '/clients'
51
+ Proxy.new(connection, path_prefix)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,67 @@
1
+ class Twelve
2
+
3
+ # API module encapsulates all of the API endpoints
4
+ #
5
+ module API
6
+
7
+ # The Gauges module handles Gauges on Gauges
8
+ #
9
+ module Gauges
10
+
11
+ # Gauges::Proxy inherits from Twelve::Proxy and
12
+ # enables defining methods on the proxy object
13
+ #
14
+ class Proxy < ::Twelve::ResourceProxy
15
+ include Twelve::API::Gauges::Shares
16
+ include Twelve::API::Gauges::Content
17
+ include Twelve::API::Gauges::Referrers
18
+ include Twelve::API::Gauges::Traffic
19
+ include Twelve::API::Gauges::Resolutions
20
+ include Twelve::API::Gauges::Technology
21
+ include Twelve::API::Gauges::Terms
22
+ include Twelve::API::Gauges::Engines
23
+ include Twelve::API::Gauges::Locations
24
+
25
+ # Creates a gauge
26
+ #
27
+ # attributes - Hash of attributes
28
+ #
29
+ # Returns json
30
+ #
31
+ def create(attributes)
32
+ connection.post(path_prefix, attributes).body['gauge']
33
+ end
34
+
35
+ # Deletes a gauge
36
+ #
37
+ # Returns json
38
+ #
39
+ def destroy
40
+ connection.delete(path_prefix).body['gauge']
41
+ end
42
+
43
+ # Get gauges, gauge, or update gauge
44
+ #
45
+ # Returns json
46
+ #
47
+ def subject
48
+ response = if attributes
49
+ connection.put(path_prefix, attributes).body
50
+ else
51
+ connection.get(path_prefix).body
52
+ end
53
+ @subject ||= path_prefix == '/gauges' ? response['gauges'] : response['gauge']
54
+ end
55
+ end
56
+
57
+ # Get, Create, Update, and Delete Gauges
58
+ #
59
+ # Returns json
60
+ #
61
+ def gauges(id=nil, attributes=nil)
62
+ path_prefix = id ? "/gauges/#{id}" : '/gauges'
63
+ Proxy.new(connection, path_prefix, attributes)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,36 @@
1
+ class Twelve
2
+
3
+ # API module encapsulates all of the API endpoints
4
+ #
5
+ module API
6
+
7
+ # The Gauges module handles Gauges on Gauges
8
+ #
9
+ module Gauges
10
+
11
+ # The Content module handles top content
12
+ #
13
+ module Content
14
+
15
+ # Returns top content for a gauge
16
+ #
17
+ # *args - Date string & options hash
18
+ #
19
+ # Returns json
20
+ #
21
+ def content(*args)
22
+ attributes = {}
23
+
24
+ connection.get do |request|
25
+ request.url "#{path_prefix}/content"
26
+
27
+ args.each do |arg|
28
+ request.params['page'] = arg[:page].to_s if arg.is_a?(Hash) && arg.has_key?(:page)
29
+ request.params['date'] = arg if arg.is_a?(String)
30
+ end
31
+ end.body
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end