sklik-api 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
@@ -68,7 +68,8 @@ Example of input hash
68
68
  def self.find args = {}
69
69
  out = []
70
70
  super(NAME, args[:customer_id]).each do |campaign|
71
- if args[:campaign_id].nil? || (args[:campaign_id] && args[:campaign_id].to_i == campaign[:id].to_i)
71
+ if (args[:campaign_id].nil? || (args[:campaign_id] && args[:campaign_id].to_i == campaign[:id].to_i)) && #find by campaign id
72
+ (args[:status].nil? || (args[:status] && args[:status] == fix_status(campaign))) # find by status
72
73
  out << SklikApi::Campaign.new(
73
74
  :campaign_id => campaign[:id],
74
75
  :customer_id => args[:customer_id],
@@ -109,6 +110,10 @@ Example of input hash
109
110
  end
110
111
  end
111
112
 
113
+ def adgroups
114
+ Adgroup.find(self)
115
+ end
116
+
112
117
  def to_hash
113
118
  if @campaign_data
114
119
  @campaign_data
@@ -173,7 +178,7 @@ Example of input hash
173
178
  @args.merge!(args)
174
179
  save
175
180
  end
176
-
181
+
177
182
  def save
178
183
  if @args[:campaign_id] #do update
179
184
  #get current status of campaign
@@ -76,6 +76,25 @@ Example of input hash
76
76
  end
77
77
  end
78
78
 
79
+ def keywords_stats from, to
80
+ output = []
81
+ keywords = Keyword.find(self)
82
+ keywords.in_groups_of(100, false).each do |keywords_group|
83
+ out = connection.call("keywords.stats", keywords_group.collect{|k| k.args[:keyword_id]}, from, to ) { |param|
84
+ param[:keywordStats]
85
+ }
86
+ out.each do |kw_stats|
87
+ kws = keywords_group.select{|k| k.args[:keyword_id] == kw_stats["keywordId"]}
88
+ if kws.size == 1
89
+ kw = keywords_group.delete(kws.first)
90
+ kw.stats = {:fulltext => underscore_hash_keys(kw_stats["stats"]) }
91
+ output << kw
92
+ end
93
+ end
94
+ end
95
+ output
96
+ end
97
+
79
98
  def to_hash
80
99
  if @adgroup_data
81
100
  @adgroup_data
@@ -78,7 +78,7 @@ Example of input hash
78
78
  end
79
79
  end
80
80
 
81
- def to_hash
81
+ def to_hash
82
82
  if @adtext_data
83
83
  @adtext_data
84
84
  else
@@ -69,35 +69,35 @@ Example of input hash
69
69
  end
70
70
 
71
71
  def self.find adgroup, args = {}
72
- out = []
73
- super(NAME, adgroup.args[:adgroup_id]).each do |keyword|
74
- if args[:keyword_id].nil? || (args[:keyword_id] && args[:keyword_id].to_i == keyword[:id].to_i)
75
- out << SklikApi::Keyword.new(
76
- adgroup,
77
- :keyword_id => keyword[:id],
78
- :keyword => apply_math_type(keyword[:name], keyword[:matchType] ),
79
- :status => fix_status(keyword)
80
- )
81
- end
82
- end
83
- out
84
- end
72
+ out = []
73
+ super(NAME, adgroup.args[:adgroup_id]).each do |keyword|
74
+ if args[:keyword_id].nil? || (args[:keyword_id] && args[:keyword_id].to_i == keyword[:id].to_i)
75
+ out << SklikApi::Keyword.new(
76
+ adgroup,
77
+ :keyword_id => keyword[:id],
78
+ :keyword => apply_math_type(keyword[:name], keyword[:matchType] ),
79
+ :status => fix_status(keyword)
80
+ )
81
+ end
82
+ end
83
+ out
84
+ end
85
85
 
86
- def self.fix_status keyword
87
- if keyword[:removed] == true
88
- return :stopped
89
- elsif keyword[:status] == "active"
90
- return :running
91
- elsif keyword[:status] == "suspend"
92
- return :paused
93
- elsif keyword[:status] == "nonactive"
94
- return :paused_by_low_cpc
95
- else
96
- return :unknown
97
- end
98
- end
86
+ def self.fix_status keyword
87
+ if keyword[:removed] == true
88
+ return :stopped
89
+ elsif keyword[:status] == "active"
90
+ return :running
91
+ elsif keyword[:status] == "suspend"
92
+ return :paused
93
+ elsif keyword[:status] == "nonactive"
94
+ return :paused_by_low_cpc
95
+ else
96
+ return :unknown
97
+ end
98
+ end
99
99
 
100
- def to_hash
100
+ def to_hash
101
101
  if @keyword_data
102
102
  @keyword_data
103
103
  else
@@ -62,6 +62,20 @@ class SklikApi
62
62
  @args["#{self.class.to_s.downcase.split(":").last}_id".to_sym] = out
63
63
  @args
64
64
  end
65
+
66
+ def stats= item
67
+ @stats = item
68
+ end
69
+
70
+ def stats
71
+ @stats ||= {}
72
+ end
73
+
74
+ def get_stats from, to
75
+ @stats ||= connection.call("#{self.class::NAME}.stats", @args["#{self.class.name.to_s.split("::").last.underscore}_id".to_sym], from, to ) { |param|
76
+ {:fulltext => underscore_hash_keys(param[:fulltext]), :context => underscore_hash_keys(param[:context]) }
77
+ }
78
+ end
65
79
 
66
80
  def update_object
67
81
  out = connection.call("#{self.class::NAME}.setAttributes", *update_args ) { |param| true }
@@ -78,6 +92,10 @@ class SklikApi
78
92
  def to_hash
79
93
  raise(NoMethodError, "Please implement 'to_hash' method in class: #{self.class} - should return hash which contains all data")
80
94
  end
95
+
96
+ def underscore_hash_keys hash
97
+ hash.inject({ }) { |x, (k,v)| x[k.underscore.to_sym] = v; x }
98
+ end
81
99
  end
82
100
  end
83
101
  end
data/sklik-api.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sklik-api"
8
- s.version = "0.0.10"
8
+ s.version = "0.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ondrej Bartas"]
12
- s.date = "2012-07-11"
12
+ s.date = "2012-07-12"
13
13
  s.description = "Sklik advertising PPC api for creating campaigns and updating them when they runs"
14
14
  s.email = "ondrej@bartas.cz"
15
15
  s.extra_rdoc_files = [
@@ -70,6 +70,12 @@ class CampaignTest < Test::Unit::TestCase
70
70
  assert SklikApi::Campaign.find(:customer_id => 192495).size > 0
71
71
  end
72
72
 
73
+ should "return stats" do
74
+ assert_nothing_raised do
75
+ SklikApi::Campaign.find(:campaign_id => 390265).first.get_stats Date.today, Date.today
76
+ end
77
+ end
78
+
73
79
  should "have hash stored inside" do
74
80
  assert_equal @campaign.args, @test_campaign_hash
75
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sklik-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-11 00:00:00.000000000 Z
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70173302687720 !ruby/object:Gem::Requirement
16
+ requirement: &70121742435280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70173302687720
24
+ version_requirements: *70121742435280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: unicode
27
- requirement: &70173302687020 !ruby/object:Gem::Requirement
27
+ requirement: &70121742434640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.4.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70173302687020
35
+ version_requirements: *70121742434640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: text
38
- requirement: &70173302720720 !ruby/object:Gem::Requirement
38
+ requirement: &70121742433900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.2.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70173302720720
46
+ version_requirements: *70121742433900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: i18n
49
- requirement: &70173302720120 !ruby/object:Gem::Requirement
49
+ requirement: &70121742467680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.6.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70173302720120
57
+ version_requirements: *70121742467680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70173302719460 !ruby/object:Gem::Requirement
60
+ requirement: &70121742467120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 3.1.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70173302719460
68
+ version_requirements: *70121742467120
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
- requirement: &70173302718740 !ruby/object:Gem::Requirement
71
+ requirement: &70121742466380 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70173302718740
79
+ version_requirements: *70121742466380
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: shoulda-context
82
- requirement: &70173302718160 !ruby/object:Gem::Requirement
82
+ requirement: &70121742465720 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70173302718160
90
+ version_requirements: *70121742465720
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: turn
93
- requirement: &70173302717580 !ruby/object:Gem::Requirement
93
+ requirement: &70121742465120 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.8.2
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70173302717580
101
+ version_requirements: *70121742465120
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: minitest
104
- requirement: &70173302717020 !ruby/object:Gem::Requirement
104
+ requirement: &70121742464560 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70173302717020
112
+ version_requirements: *70121742464560
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: ansi
115
- requirement: &70173302716340 !ruby/object:Gem::Requirement
115
+ requirement: &70121742463940 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.2.5
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70173302716340
123
+ version_requirements: *70121742463940
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: jeweler
126
- requirement: &70173302715660 !ruby/object:Gem::Requirement
126
+ requirement: &70121742463300 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 1.8.3
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70173302715660
134
+ version_requirements: *70121742463300
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: fakeweb
137
- requirement: &70173302715020 !ruby/object:Gem::Requirement
137
+ requirement: &70121742462620 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70173302715020
145
+ version_requirements: *70121742462620
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: thin
148
- requirement: &70173302714400 !ruby/object:Gem::Requirement
148
+ requirement: &70121742461960 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70173302714400
156
+ version_requirements: *70121742461960
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: shotgun
159
- requirement: &70173302713820 !ruby/object:Gem::Requirement
159
+ requirement: &70121742461380 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: '0'
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *70173302713820
167
+ version_requirements: *70121742461380
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: rcov
170
- requirement: &70173302713200 !ruby/object:Gem::Requirement
170
+ requirement: &70121742460800 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - =
@@ -175,7 +175,7 @@ dependencies:
175
175
  version: 0.9.10
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *70173302713200
178
+ version_requirements: *70121742460800
179
179
  description: Sklik advertising PPC api for creating campaigns and updating them when
180
180
  they runs
181
181
  email: ondrej@bartas.cz
@@ -222,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  segments:
224
224
  - 0
225
- hash: -4528822956475968733
225
+ hash: -547141581635858768
226
226
  required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  none: false
228
228
  requirements: