google_api 1.0.3 → 1.1.0.beta

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.
@@ -0,0 +1,28 @@
1
+ module GoogleApi
2
+ module Shorten
3
+
4
+ CONFIGURATION = {}
5
+
6
+ # Session
7
+ autoload :Session, 'google_api/shorten/session'
8
+
9
+ # Url
10
+ autoload :Url, 'google_api/shorten/url/url'
11
+ autoload :Insert, 'google_api/shorten/url/insert'
12
+ autoload :List, 'google_api/shorten/url/list'
13
+ autoload :Get, 'google_api/shorten/url/get'
14
+
15
+ def self.insert(url)
16
+ Insert.new(url)
17
+ end
18
+
19
+ def self.list
20
+ List.new
21
+ end
22
+
23
+ def self.get(url, projection = 'FULL')
24
+ Get.new(url, projection)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ module GoogleApi
2
+ module Shorten
3
+ class Get < Url
4
+
5
+ attr_reader :short_url
6
+ attr_reader :projection
7
+ attr_reader :data
8
+
9
+ PROJECTION_LIST = ['FULL', 'ANALYTICS_CLICKS', 'ANALYTICS_TOP_STRINGS']
10
+
11
+ def initialize(short_url, projection)
12
+ @short_url = short_url
13
+ @projection = projection.upcase
14
+
15
+ unless PROJECTION_LIST.include?(projection)
16
+ raise GoogleApi::ShortenError, "Invalid projection. Must be #{PROJECTION_LIST.join(',')}."
17
+ end
18
+
19
+ get
20
+ end
21
+
22
+ private
23
+
24
+ def get
25
+ @data = JSON.parse(_session.client.execute( api_method: _session.api.url.get,
26
+ parameters: { shortUrl: @short_url,
27
+ projection: @projection } ).response.env[:body])
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ module GoogleApi
2
+ module Shorten
3
+ class Insert < Url
4
+
5
+ attr_reader :long_url
6
+ attr_reader :short_url
7
+
8
+ def initialize(long_url)
9
+ @long_url = long_url
10
+
11
+ get
12
+ end
13
+
14
+ def details(projection = 'FULL')
15
+ Shorten.get(@short_url, projection)
16
+ end
17
+
18
+ private
19
+
20
+ def get
21
+ @short_url = _session.client.execute( api_method: _session.api.url.insert,
22
+ body: { longUrl: @long_url }.to_json,
23
+ headers: {'Content-Type' => 'application/json'} ).data.id
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module GoogleApi
2
+ module Shorten
3
+ class List < Url
4
+
5
+ def initialize
6
+ get
7
+ end
8
+
9
+ def count
10
+ @data['totalItems']
11
+ end
12
+
13
+ def items
14
+ @data['items']
15
+ end
16
+
17
+ private
18
+
19
+ def get
20
+ @data = JSON.parse(_session.client.execute( api_method: _session.api.url.list,
21
+ parameters: { projection: 'FULL' } ).response.env[:body])
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module GoogleApi
2
+ module Shorten
3
+ class Url
4
+
5
+ def _session
6
+ Session
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module GoogleApi
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0.beta"
3
3
  end
@@ -7,14 +7,6 @@ describe "GoogleApi::Ga::Data" do
7
7
 
8
8
 
9
9
 
10
- # Rows
11
- # -------------------------------------------------------------------------------------------------
12
- it "rows" do
13
- lambda { @data.new.rows }.should raise_error(GoogleApi::SessionError)
14
- end
15
-
16
-
17
-
18
10
  # Default values
19
11
  # -------------------------------------------------------------------------------------------------
20
12
  it "default values" do
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
5
- prerelease:
4
+ version: 1.1.0.beta
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ondřej Moravčík
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-21 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-api-client
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- description: Simple Google Api. Include google analytics.
62
+ description: Simple Google Api. Include google analytics, url shortener.
63
63
  email:
64
64
  - moravcik.ondrej@gmail.com
65
65
  executables: []
@@ -80,13 +80,11 @@ files:
80
80
  - lib/google_api/configuration.rb
81
81
  - lib/google_api/core_ext/hash.rb
82
82
  - lib/google_api/core_ext/string.rb
83
- - lib/google_api/date.rb
84
- - lib/google_api/ga.rb
85
83
  - lib/google_api/ga/data.rb
86
84
  - lib/google_api/ga/data/data_dsl.rb
87
85
  - lib/google_api/ga/data/filters_dsl.rb
88
86
  - lib/google_api/ga/data/segment_dsl.rb
89
- - lib/google_api/ga/helper.rb
87
+ - lib/google_api/ga/ga.rb
90
88
  - lib/google_api/ga/management/account.rb
91
89
  - lib/google_api/ga/management/goal.rb
92
90
  - lib/google_api/ga/management/management.rb
@@ -94,6 +92,14 @@ files:
94
92
  - lib/google_api/ga/management/segment.rb
95
93
  - lib/google_api/ga/management/webproperty.rb
96
94
  - lib/google_api/ga/session.rb
95
+ - lib/google_api/session/session.rb
96
+ - lib/google_api/session/session_methods.rb
97
+ - lib/google_api/shorten/session.rb
98
+ - lib/google_api/shorten/shorten.rb
99
+ - lib/google_api/shorten/url/get.rb
100
+ - lib/google_api/shorten/url/insert.rb
101
+ - lib/google_api/shorten/url/list.rb
102
+ - lib/google_api/shorten/url/url.rb
97
103
  - lib/google_api/version.rb
98
104
  - spec/lib/google_api_cache_spec.rb
99
105
  - spec/lib/google_api_ga_data_spec.rb
@@ -115,15 +121,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
121
  required_rubygems_version: !ruby/object:Gem::Requirement
116
122
  none: false
117
123
  requirements:
118
- - - ! '>='
124
+ - - ! '>'
119
125
  - !ruby/object:Gem::Version
120
- version: '0'
126
+ version: 1.3.1
121
127
  requirements: []
122
128
  rubyforge_project:
123
129
  rubygems_version: 1.8.23
124
130
  signing_key:
125
131
  specification_version: 3
126
- summary: Simple Google Api. Include google analytics.
132
+ summary: Simple Google Api. Include google analytics, url shortener.
127
133
  test_files:
128
134
  - spec/lib/google_api_cache_spec.rb
129
135
  - spec/lib/google_api_ga_data_spec.rb
@@ -1,58 +0,0 @@
1
- require "date"
2
-
3
- module GoogleApi
4
- module Date
5
-
6
- DATE_FORMAT = /\A[0-9]{4}-[0-9]{2}-[0-9]{2}\Z/
7
-
8
- def to_date(date)
9
- if date.is_a?(String)
10
- unless date =~ DATE_FORMAT
11
- raise GoogleApi::DateError, "Date: #{date} must match with #{DATE_FORMAT}."
12
- end
13
-
14
- date = Date.parse(date)
15
- end
16
-
17
- date.to_date
18
- end
19
-
20
- def now
21
- Date.today
22
- end
23
-
24
- def prev_month
25
- Date.today.prev_month
26
- end
27
-
28
- def more_months?(d1, d2)
29
-
30
- d1 = Date.parse(d1) if d1.is_a?(String)
31
- d2 = Date.parse(d2) if d2.is_a?(String)
32
-
33
- d1.month != d2.month
34
- end
35
-
36
- def more_years?(d1, d2)
37
-
38
- d1 = Date.parse(d1) if d1.is_a?(String)
39
- d2 = Date.parse(d2) if d2.is_a?(String)
40
-
41
- d1.year != d2.year
42
- end
43
-
44
- def day_older?(date)
45
-
46
- if date.is_a?(String)
47
- date = Date.parse(date)
48
- end
49
-
50
- if (Date.today <=> date.to_date) > 0
51
- return true
52
- end
53
-
54
- return false
55
- end
56
-
57
- end
58
- end
@@ -1,41 +0,0 @@
1
- module GoogleApi
2
- module Ga
3
- module Helper
4
-
5
- # Same as get but automaticly add day, month and year to dimension
6
- #
7
- # Also check cache
8
- #
9
- def get_by_day(parameters, start_date = prev_month, end_date = now, expire = nil)
10
-
11
- [:dimensions, :sort].each do |param|
12
- parameters[param] = [] unless parameters[param]
13
-
14
- if parameters[param].is_a?(String) || parameters[param].is_a?(Symbol)
15
- parameters[param] = [parameters[param]]
16
- end
17
- end
18
-
19
- parameters[:dimensions] << :day
20
-
21
- if more_years?(start_date, end_date)
22
- parameters[:dimensions] << :month
23
- parameters[:dimensions] << :year
24
-
25
- parameters[:sort] << :year
26
- parameters[:sort] << :month
27
-
28
- elsif more_months?(start_date, end_date)
29
- parameters[:dimensions] << :month
30
-
31
- parameters[:sort] << :month
32
- end
33
-
34
- parameters[:sort] << :day
35
-
36
- get(parameters, start_date, end_date, expire)
37
- end
38
-
39
- end
40
- end
41
- end