citygrid_api 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.sass-cache/c6f2c767b164f077e5b9fb1f18a7886d7c755211/test.scssc +0 -0
  2. data/README.rdoc +42 -13
  3. data/Rakefile +2 -2
  4. data/VERSION +1 -1
  5. data/citygrid_api.gemspec +23 -12
  6. data/citygrid_api.yml.sample +10 -2
  7. data/citygrid_api.yml.sandbox +46 -0
  8. data/dashboard.rb +1 -1
  9. data/fixtures/vcr_cassettes/AdGroupCriterion_mutate.yml +3 -3
  10. data/fixtures/vcr_cassettes/AdGroupCriterion_search.yml +3 -3
  11. data/fixtures/vcr_cassettes/Adding_a_place.yml +4 -4
  12. data/fixtures/vcr_cassettes/Geo.yml +30 -13
  13. data/fixtures/vcr_cassettes/Getting_an_offer.yml +413 -0
  14. data/fixtures/vcr_cassettes/Getting_an_offer_by_listing_ID.yml +12 -12
  15. data/fixtures/vcr_cassettes/Import_a_cg_account.yml +28 -16
  16. data/fixtures/vcr_cassettes/Initiating_a_Details.yml +14 -30
  17. data/fixtures/vcr_cassettes/Initiating_new_MultiDetails.yml +13 -13
  18. data/fixtures/vcr_cassettes/Mutating_AdGroup_Ads.yml +4 -4
  19. data/fixtures/vcr_cassettes/Report_summary_daily.yml +34 -34
  20. data/fixtures/vcr_cassettes/Report_summary_user_actions.yml +14 -10
  21. data/fixtures/vcr_cassettes/Search_Ad_Group_by_Campaign_Id.yml +3 -3
  22. data/fixtures/vcr_cassettes/Search_Billing_by_Campaign_Id.yml +31 -12
  23. data/fixtures/vcr_cassettes/Search_account_manager_by_Campaign_Id.yml +25 -12
  24. data/fixtures/vcr_cassettes/Searching_AdGroup_Geo.yml +6 -6
  25. data/fixtures/vcr_cassettes/Searching_budgets.yml +31 -12
  26. data/fixtures/vcr_cassettes/Searching_categories_by_listing_id.yml +3 -3
  27. data/fixtures/vcr_cassettes/Searching_categories_by_query.yml +3 -3
  28. data/fixtures/vcr_cassettes/Upload_an_image_Add_a_preview.yml +31 -12
  29. data/fixtures/vcr_cassettes/{Method_of_Payment_mutate.yml → create_a_mop.yml} +24 -12
  30. data/fixtures/vcr_cassettes/create_an_offer.yml +51 -0
  31. data/fixtures/vcr_cassettes/create_campaign.yml +5 -5
  32. data/fixtures/vcr_cassettes/create_campaign_then_create_ad_group_belonging_to_campaign.yml +61 -0
  33. data/fixtures/vcr_cassettes/create_campaign_then_create_ad_group_belonging_to_campaign_then_search_.yml +91 -0
  34. data/fixtures/vcr_cassettes/getting_reviews_by_listing_id.yml +91 -0
  35. data/fixtures/vcr_cassettes/log_in_a_session.yml +3 -3
  36. data/fixtures/vcr_cassettes/log_in_a_session_mutate_places.yml +7 -7
  37. data/fixtures/vcr_cassettes/query_account_type_by_id.yml +24 -12
  38. data/fixtures/vcr_cassettes/search_for_an_account_by_id.yml +24 -13
  39. data/fixtures/vcr_cassettes/search_for_an_account_by_name.yml +27 -17
  40. data/fixtures/vcr_cassettes/search_for_call_detail_by_campaign.yml +49 -0
  41. data/fixtures/vcr_cassettes/search_for_mop_by_account_id.yml +65 -0
  42. data/fixtures/vcr_cassettes/searching_for_a_CityGrid_listing.yml +57 -53
  43. data/fixtures/vcr_cassettes/searching_for_a_special_CityGrid_listing.yml +10 -10
  44. data/fixtures/vcr_cassettes/user_log_in_with_raw_API.yml +24 -0
  45. data/fixtures/vcr_cassettes/user_log_in_with_session.yml +24 -0
  46. data/lib/citygrid/api/accounts/account.rb +2 -2
  47. data/lib/citygrid/api/accounts/method_of_payment.rb +2 -2
  48. data/lib/citygrid/api/accounts/user.rb +8 -4
  49. data/lib/citygrid/api/advertising/account_manager.rb +1 -1
  50. data/lib/citygrid/api/advertising/ad_group.rb +2 -2
  51. data/lib/citygrid/api/advertising/ad_group_ad.rb +2 -2
  52. data/lib/citygrid/api/advertising/ad_group_criterion.rb +2 -2
  53. data/lib/citygrid/api/advertising/ad_group_geo.rb +2 -2
  54. data/lib/citygrid/api/advertising/billing.rb +2 -1
  55. data/lib/citygrid/api/advertising/budget.rb +2 -2
  56. data/lib/citygrid/api/advertising/call_detail.rb +2 -2
  57. data/lib/citygrid/api/advertising/campaign.rb +2 -2
  58. data/lib/citygrid/api/advertising/category.rb +2 -2
  59. data/lib/citygrid/api/advertising/geolocation.rb +2 -2
  60. data/lib/citygrid/api/advertising/image.rb +3 -3
  61. data/lib/citygrid/api/advertising/offers.rb +10 -0
  62. data/lib/citygrid/api/advertising/places.rb +2 -2
  63. data/lib/citygrid/api/content/offers.rb +11 -2
  64. data/lib/citygrid/api/content/places.rb +1 -1
  65. data/lib/citygrid/api/content/response.rb +14 -0
  66. data/lib/citygrid/api/content/reviews.rb +5 -2
  67. data/lib/citygrid/api/mutable.rb +13 -0
  68. data/lib/citygrid/api/searchable.rb +4 -6
  69. data/lib/citygrid/api.rb +70 -52
  70. data/lib/citygrid/session.rb +5 -9
  71. data/lib/citygrid.rb +28 -1
  72. data/test/api/accounts/test_account.rb +53 -32
  73. data/test/api/accounts/test_method_of_payment.rb +40 -43
  74. data/test/api/accounts/test_user.rb +16 -0
  75. data/test/api/advertising/test_call_detail.rb +17 -2
  76. data/test/api/advertising/test_offers.rb +33 -0
  77. data/test/api/advertising/test_places.rb +18 -0
  78. data/test/api/content/test_offers.rb +14 -14
  79. data/test/api/content/test_response.rb +51 -0
  80. data/test/api/content/test_reviews.rb +11 -0
  81. data/test/helper.rb +18 -11
  82. metadata +41 -29
  83. data/README +0 -21
  84. data/citygrid_api.yml.backup +0 -35
  85. data/fixtures/vcr_cassettes/Call_Detail_by_campaign.yml +0 -79
  86. data/fixtures/vcr_cassettes/Method_of_Payment_search.yml +0 -59
  87. data/lib/citygrid/api/mutatable.rb +0 -15
@@ -2,8 +2,8 @@ class CityGrid
2
2
  class API
3
3
  class Advertising
4
4
  class Category < Advertising
5
- extend CityGrid::API::Mutatable
6
- extend CityGrid::API::Searchable
5
+ include CityGrid::API::Mutable
6
+ include CityGrid::API::Searchable
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ class CityGrid
2
2
  class API
3
3
  class Advertising
4
4
  class GeoLocation < Advertising
5
- extend CityGrid::API::Mutatable
6
- extend CityGrid::API::Searchable
5
+ include CityGrid::API::Mutable
6
+ include CityGrid::API::Searchable
7
7
  end
8
8
  end
9
9
  end
@@ -13,9 +13,9 @@ class CityGrid
13
13
  :body => {"mutateOperationListResource" => [
14
14
  {
15
15
  "operand" => {
16
- "image_type" => type,
17
- "image_name" => name,
18
- "image_format" => format,
16
+ "imageType" => type,
17
+ "imageName" => name,
18
+ "imageFormat" => format,
19
19
  "image" => image_data
20
20
  },
21
21
  "operator" => "ADD",
@@ -0,0 +1,10 @@
1
+ class CityGrid
2
+ class API
3
+ class Advertising
4
+ class Offers < Advertising
5
+ include CityGrid::API::Mutable
6
+ include CityGrid::API::Searchable
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,8 +2,8 @@ class CityGrid
2
2
  class API
3
3
  class Advertising
4
4
  class Places < Advertising
5
- extend CityGrid::API::Mutatable
6
- extend CityGrid::API::Searchable
5
+ include CityGrid::API::Mutable
6
+ include CityGrid::API::Searchable
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,17 @@ class CityGrid
2
2
  class API
3
3
  class Content
4
4
  class Offers < Content
5
- define_action :where, :get, "search/where", :auth_token => false, :publisher => true, :client_ip => true
6
- define_action :places, :get, "search/places", :auth_token => false, :publisher => true, :client_ip => true
5
+ define_action :where, :get, "search/where",
6
+ :auth_token => false,
7
+ :publisher => true,
8
+ :client_ip => true,
9
+ :format => true
10
+
11
+ define_action :places, :get, "search/places",
12
+ :auth_token => false,
13
+ :publisher => true,
14
+ :client_ip => true,
15
+ :format => true
7
16
  end
8
17
  end
9
18
  end
@@ -2,7 +2,7 @@ class CityGrid
2
2
  class API
3
3
  class Content
4
4
  class Places < Content
5
- extend CityGrid::API::Mutatable
5
+ include CityGrid::API::Mutable
6
6
 
7
7
  define_action :detail, :get, "detail", :auth_token => false, :publisher => true, :client_ip => true
8
8
  define_action :search, :get, "search/where", :auth_token => false, :publisher => true, :client_ip => true
@@ -0,0 +1,14 @@
1
+ class CityGrid
2
+ class API
3
+ class Content
4
+ class Response < Content
5
+ include CityGrid::API::Mutable
6
+ define_action :get, :get, "get",
7
+ :auth_token => true,
8
+ :publisher => true,
9
+ :client_ip => true,
10
+ :format => true
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,8 +2,11 @@ class CityGrid
2
2
  class API
3
3
  class Content
4
4
  class Reviews < Content
5
- base_uri "api.citygridmedia.com"
6
- endpoint "/content/reviews/v2/search/where"
5
+ define_action :where, :get, "search/where",
6
+ :auth_token => false,
7
+ :publisher => true,
8
+ :client_ip => true,
9
+ :format => true
7
10
  end
8
11
  end
9
12
  end
@@ -0,0 +1,13 @@
1
+ # /mutate endpoint
2
+
3
+ class CityGrid
4
+ class API
5
+ module Mutable
6
+ def self.included base
7
+ base.define_action :mutate, :post, "mutate",
8
+ :auth_token => true,
9
+ :format => false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -3,12 +3,10 @@
3
3
  class CityGrid
4
4
  class API
5
5
  module Searchable
6
- def search options = {}
7
- token = extract_auth_token options
8
- request_and_handle :get,
9
- "#{endpoint}/get",
10
- :query => options,
11
- :headers => merge_headers("authToken" => token)
6
+ def self.included base
7
+ base.define_action :search, :get, "get",
8
+ :auth_token => true,
9
+ :format => true
12
10
  end
13
11
  end
14
12
  end
data/lib/citygrid/api.rb CHANGED
@@ -4,14 +4,13 @@ require "json"
4
4
  class CityGrid
5
5
  class API
6
6
  include HTTParty
7
- format :json
8
7
  #debug_output $stderr
9
8
 
10
9
  DEFAULT_HEADERS = {
11
10
  "Accept" => "application/json",
12
11
  "Content-Type" => "Application/JSON"}
13
12
 
14
- DEFAULT_DEFINE_OPTIONS = {
13
+ DEFAULT_ACTION_OPTIONS = {
15
14
  :auth_token => false,
16
15
  :format => true,
17
16
  :publisher => false,
@@ -26,8 +25,8 @@ class CityGrid
26
25
  # ip: pass IP, needed for content
27
26
  # format: pass JSON flag
28
27
 
29
- define_options = DEFAULT_DEFINE_OPTIONS.merge define_options
30
-
28
+ define_options = DEFAULT_ACTION_OPTIONS.merge define_options
29
+
31
30
  define_singleton_method name.intern do |*args|
32
31
  options = args.first.clone || {}
33
32
  params = {}
@@ -36,7 +35,7 @@ class CityGrid
36
35
 
37
36
  headers = API::DEFAULT_HEADERS.clone
38
37
 
39
- headers.merge! "authToken" => token if define_options[:auth_token]
38
+ headers.merge! "authToken" => token if define_options[:auth_token] && token
40
39
 
41
40
  options.merge! "format" => "json" if define_options[:format]
42
41
  options.merge! "publisher" => CityGrid.publisher if define_options[:publisher]
@@ -91,66 +90,77 @@ class CityGrid
91
90
  http_method = HTTP_METHODS[http_method.to_s]
92
91
  raise "Unknown http method: #{http_method}" unless http_method
93
92
  end
94
-
93
+
95
94
  req_options = default_options.dup
96
95
  req_options = req_options.merge(options)
97
-
96
+
97
+ raise ConfigurationError.new "No endpoint defined" if !path || path.empty?
98
+ raise ConfigurationError.new "No hostname defined" if !req_options[:base_uri] || req_options[:base_uri].empty?
99
+
98
100
  req = HTTParty::Request.new http_method, path, req_options
99
- error = nil
100
101
 
101
- begin
102
+
103
+ begin
102
104
  response = req.perform
103
105
  rescue => ex
104
- puts "Something went wrong with Request.perform"
105
- error = ex
106
- rescue Psych::SyntaxError => ex
107
- puts "Something went wrong with Request.perform, Psych:SyntaxError"
108
- error = ex
109
- end
110
-
111
- if defined?(Rails.logger)
112
- Rails.logger.info req.to_curl
113
- else
114
- puts req.to_curl
115
- end
116
-
117
- unless error
118
- if !response.parsed_response.is_a?(Hash)
119
- error = InvalidResponseFormat.new response
120
- elsif response["errors"]
121
- error = Error.new response["errors"], response
106
+ raise RequestError.new req, ex
107
+ ensure
108
+ if defined?(Rails.logger)
109
+ Rails.logger.info req.to_curl
122
110
  else
123
- return CityGrid::API::Response.new response
111
+ puts req.to_curl
124
112
  end
125
113
  end
126
114
 
127
- if error
128
- puts "an error happened"
129
- ap error
130
- #raise error
115
+ if !response.parsed_response.is_a?(Hash)
116
+ raise ResponseParseError.new req, response
117
+ elsif response["errors"]
118
+ raise ResponseError.new req, response["errors"], response
119
+ elsif response["message"] && response["message"] == "Invalid Token or Expired"
120
+ raise InvalidAuthToken.new
121
+ else
122
+ return CityGrid::API::Response.new response
131
123
  end
124
+
125
+ rescue => ex
126
+ raise ex if CityGrid.raise_errors?
132
127
  end
133
128
  end
134
129
 
135
130
  # ERRORS
136
- class GenericError < StandardError
137
- attr_reader :httparty, :message
138
-
139
- def initialize msg, response = nil
140
- @message = msg
141
- @httparty = response
131
+ class APIError < StandardError
132
+ attr_accessor :request
133
+
134
+ def initialize msg, request
135
+ super msg
142
136
  end
143
137
  end
144
-
145
- class Error < GenericError
146
- def initialize errors, response
147
- super errors.first["error"], response
138
+
139
+ class ResponseError < APIError
140
+ attr_accessor :errors, :response
141
+
142
+ def initialize request, errors, response
143
+ self.errors = errors
144
+ self.response = response
145
+
146
+ super "API returned error message", request
148
147
  end
149
148
  end
150
-
151
- class InvalidResponseFormat < GenericError
152
- attr_accessor :server_msg, :description
153
- def initialize response = nil
149
+
150
+ class RequestError < APIError
151
+ attr_accessor :inner_exception
152
+
153
+ def initialize request, inner_exception, msg = nil
154
+ self.inner_exception = inner_exception
155
+ self.request = request
156
+ super msg || "Error while performing request: #{inner_exception.message}", request
157
+ end
158
+ end
159
+
160
+ class ResponseParseError < APIError
161
+ attr_accessor :server_msg, :description, :raw_response
162
+ def initialize request, response
163
+ self.raw_response = response
154
164
  # parse Tomcat error report
155
165
  if response.match /<title>Apache Tomcat.* - Error report<\/title>/
156
166
  response.scan(/<p><b>(message|description)<\/b> *<u>(.*?)<\/u><\/p>/).each do |match|
@@ -168,24 +178,32 @@ class CityGrid
168
178
  Unexpected response format. Expected response to be a hash, but was instead:\n#{error_body}\n
169
179
  EOS
170
180
 
171
- super msg, error_body
181
+ super msg, request
172
182
  else
173
183
  msg = <<-EOS
174
184
  Unexpected response format. Expected response to be a hash, but was instead:\n#{response.parsed_response}\n
175
185
  EOS
176
186
 
177
- super msg, response
187
+ super msg, request
178
188
  end
179
189
  end
180
190
  end
181
191
 
182
- class MissingAuthToken < GenericError
183
- def initialize
192
+ class InvalidAuthToken < StandardError
193
+ def initialize message = "Invalid Token or Expired"
184
194
  super message
185
195
  end
196
+ end
186
197
 
187
- def message
188
- "Missing authToken - token is required"
198
+ class MissingAuthToken < StandardError
199
+ def initialize
200
+ super "Missing authToken - token is required"
201
+ end
202
+ end
203
+
204
+ class ConfigurationError < StandardError
205
+ def initialize message = "Invalid Configuration"
206
+ super message
189
207
  end
190
208
  end
191
209
  end
@@ -26,19 +26,15 @@ class CityGrid
26
26
  end
27
27
 
28
28
  def login username, password
29
- res = CityGrid::API::Accounts::Authentication.login :username => username, :password => password
29
+ res = CityGrid::API::Accounts::User.login :username => username, :password => password
30
30
  self.username = username
31
31
 
32
- case res.code
33
- when 201
34
- self.auth_token = res.authToken
32
+
33
+ self.auth_token = res.authToken
34
+ if !auth_token.nil? && auth_token != ""
35
35
  self.logged_in = true
36
- # puts "logged in ok"
37
- when 400
38
- # puts "error"
39
- else
40
- # puts "unexpected response code"
41
36
  end
37
+
42
38
  end
43
39
 
44
40
  def call_api klass, action, options = {}
data/lib/citygrid.rb CHANGED
@@ -16,7 +16,25 @@ class CityGrid
16
16
  raise PublisherNotConfigured if !defined?(@publisher) || @publisher.nil?
17
17
  @publisher
18
18
  end
19
+
20
+ # whether api calls will throw errors or fail silently
21
+ # by default, we will raise errors
22
+ def raise_errors= v
23
+ @raise_errors = v
24
+ end
25
+
26
+ def raise_errors?
27
+ !defined?(@raise_errors) || @raise_errors
28
+ end
19
29
 
30
+ def use_vcr= v
31
+ @use_vcr = v
32
+ end
33
+
34
+ def use_vcr?
35
+ defined?(VCR) && defined?(@use_vcr) && @use_vcr
36
+ end
37
+
20
38
  def search opts = {}
21
39
  Search.new opts
22
40
  end
@@ -70,11 +88,13 @@ class CityGrid
70
88
  # if hostname is set, use it
71
89
  # otherwise if ssl is set then use ssl_hostname. fallback to default_hostname
72
90
  hostname = v["hostname"] || (v["ssl"] ? ssl_hostname : default_hostname)
91
+ throw ParseConfigurationError.new file_path, "No endpoint defined for #{k}" unless v["endpoint"]
73
92
  endpoint = v["endpoint"].start_with?("/") ? v["endpoint"] : "/#{v["endpoint"]}"
74
93
  klass.endpoint endpoint
75
94
  klass.base_uri hostname
76
95
  else
77
96
  # should not get here. value should be String or Hash
97
+ throw ParseConfigurationError.new file_path, "Invalid value type for #{k}"
78
98
  end
79
99
 
80
100
  # puts "#{klass.name} => #{klass.base_uri} : #{klass.endpoint}"
@@ -96,13 +116,20 @@ class CityGrid
96
116
  super "Endpoint is not properly configured. Run 'CityGrid.load_config'"
97
117
  end
98
118
  end
119
+
120
+ class ParseConfigurationError < StandardError
121
+ def initialize path, msg = nil
122
+ super msg ? "#{msg} at '#{path}'" : "Error parsing configuration file at '#{path}'"
123
+ end
124
+ end
125
+
99
126
  end
100
127
 
101
128
  require "citygrid/abstraction"
102
129
  require "citygrid/api"
103
130
  require "yaml"
104
131
 
105
- require "citygrid/api/mutatable"
132
+ require "citygrid/api/mutable"
106
133
  require "citygrid/api/searchable"
107
134
 
108
135
  require "citygrid/search"
@@ -19,7 +19,7 @@ context "search for an account" do
19
19
  run_with_rescue do
20
20
  SessionHelper.sales_coord.call_api CityGrid::API::Accounts::Account,
21
21
  :search,
22
- :id => 1250702
22
+ :id => 1250702
23
23
  end
24
24
  end
25
25
  should("not be empty"){ !topic.empty? }
@@ -57,9 +57,9 @@ context "import a cg account" do
57
57
  "phone" => "9001111112",
58
58
  "businessName" =>"businessProveApi",
59
59
  "address1" =>"dir-api",
60
- "city" =>"montevideo",
61
- "state" =>"Montevideo",
62
- "zipCode" =>"90069"
60
+ "city" =>"montevideo",
61
+ "state" =>"Montevideo",
62
+ "zipCode" =>"90069"
63
63
  }
64
64
  }]
65
65
  end
@@ -72,38 +72,59 @@ end
72
72
  context "create an account" do
73
73
  set :vcr, false
74
74
 
75
- username = "randuser_#{rand(10000000)}"
75
+ username = "randuser_9178989" # "randuser_#{rand(10000000)}"
76
+ email = "#{username}@a.com"
76
77
  password = "randuserpass"
77
78
 
78
- setup do
79
- SessionHelper.sales_coord.call_api CityGrid::API::Accounts::Account,
80
- :mutate,
81
- "mutateOperationListResource" => [{
82
- "operator" => "ADD",
83
- "operand" => {
84
- "firstName" => "nico-api",
85
- "lastName" => "gomez-api",
86
- "phone" => "9001111112",
87
- "email" => "#{username}@a.com",
88
- "userName" => username,
89
- "password" => password,
90
- "businessName" => "businessProveApi",
91
- "address1" => "dir-api",
92
- "city" => "montevideo",
93
- "state" => "Montevideo",
94
- "zipCode" => "90069"
95
- }
96
- }]
97
- end
98
- should("not be empty"){ !topic.empty? }
99
- should("return message OK"){ topic.accountList.first.response.message }.equals("OK")
100
- should("return response code OK"){ topic.accountList.first.response.code.to_i }.equals(200)
101
-
102
- context "then logging in" do
79
+ # setup do
80
+ # SessionHelper.sales_coord.call_api CityGrid::API::Accounts::Account,
81
+ # :mutate,
82
+ # "mutateOperationListResource" => [{
83
+ # "operator" => "ADD",
84
+ # "operand" => {
85
+ # "firstName" => "nico-api",
86
+ # "lastName" => "gomez-api",
87
+ # "phone" => "9001111112",
88
+ # "email" => email,
89
+ # "userName" => username,
90
+ # "password" => password,
91
+ # "businessName" => "businessProveApi",
92
+ # "address1" => "dir-api",
93
+ # "city" => "montevideo",
94
+ # "state" => "Montevideo",
95
+ # "zipCode" => "90069"
96
+ # }
97
+ # }]
98
+ # end
99
+ # should("not be empty"){ !topic.empty? }
100
+ # should("return message OK"){ topic.accountList.first.response.message }.equals("OK")
101
+ # should("return response code OK"){ topic.accountList.first.response.code.to_i }.equals(200)
102
+ #
103
+ # context "then logging in" do
104
+ # setup do
105
+ # CityGrid.login :username => username, :password => password
106
+ # end
107
+ # should("return an authToken"){ topic.authToken }
108
+ # end
109
+ #
110
+ # context "then validate with session" do
111
+ # setup do
112
+ # session = CityGrid.session username, password
113
+ # session.call_api CityGrid::API::Accounts::User, :validate, :oauth_token => session.auth_token
114
+ # end
115
+ #
116
+ # should("match on display_name") { topic.display_name }.equals(username)
117
+ # should("match on email") { topic.email }.equals(email)
118
+ # end
119
+ #
120
+ context "then validate with raw API" do
103
121
  setup do
104
- CityGrid.login :username => username, :password => password
122
+ session = CityGrid.session username, password
123
+ CityGrid::API::Accounts::User.validate :oauth_token => session.auth_token
105
124
  end
106
- should("return an authToken"){ topic.authToken }
125
+
126
+ should("match on display_name") { topic.display_name }.equals(username)
127
+ should("match on email") { topic.email }.equals(email)
107
128
  end
108
129
 
109
130
  end
@@ -1,50 +1,47 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'helper'))
2
2
 
3
- context "Method of Payment" do
4
- context "search" do
5
- setup do
6
- run_with_rescue do
7
- SessionHelper.kunimom.call_api CityGrid::API::Accounts::MethodOfPayment,
8
- :search,
9
- :accountId => 111
10
- end
3
+ context "search for mop by account_id" do
4
+ setup do
5
+ run_with_rescue do
6
+ SessionHelper.kunimom.call_api CityGrid::API::Accounts::MethodOfPayment,
7
+ :search,
8
+ :accountId => 111
11
9
  end
12
- should("not be empty"){ !topic.empty?}
13
- should("have MOP resources"){ !topic.mopResources.empty? }
14
10
  end
11
+ should("not be empty"){ !topic.empty?}
12
+ should("have MOP resources"){ !topic.mopResources.empty? }
13
+ end
15
14
 
16
- # API not working here
17
- context "mutate" do
18
- setup do
19
- run_with_rescue do
20
- SessionHelper.kunimom.call_api CityGrid::API::Accounts::MethodOfPayment,
21
- :mutate,
22
- "mutateOperationListResource" => [{
23
- "operator" => "ADD",
24
- "operand" => {
25
- "cardNumber" => "4112344112344113",
26
- "expirationMonth" => 12,
27
- "expirationYear" => 2012,
28
- "nameOnAccount" => "Ara Tatous",
29
- "cardType" => "Visa",
30
- "state" => "NY" ,
31
- "description" => "test addMOP",
32
- "firstName" => "Ara",
33
- "lastName" => "Tatous",
34
- "phoneNumber" => "4252838811",
35
- "address1" => "3131 Montrose Ave",
36
- "address2" => "Apt. 9",
37
- "city" => "LaCrescenta",
38
- "postalCode" => "10016",
39
- "accountId" => 2458392,
40
- "securityCode" => "719",
41
- "paymentType" => "Credit Card"
42
- }
43
- }]
44
- end
15
+ context "create a mop" do
16
+ setup do
17
+ run_with_rescue do
18
+ SessionHelper.kunimom.call_api CityGrid::API::Accounts::MethodOfPayment,
19
+ :mutate,
20
+ "mutateOperationListResource" => [{
21
+ "operator" => "ADD",
22
+ "operand" => {
23
+ "cardNumber" => "4112344112344113",
24
+ "expirationMonth" => 12,
25
+ "expirationYear" => 2012,
26
+ "nameOnAccount" => "Ara Tatous",
27
+ "cardType" => "Visa",
28
+ "state" => "NY" ,
29
+ "description" => "test addMOP",
30
+ "firstName" => "Ara",
31
+ "lastName" => "Tatous",
32
+ "phoneNumber" => "4252838811",
33
+ "address1" => "3131 Montrose Ave",
34
+ "address2" => "Apt. 9",
35
+ "city" => "LaCrescenta",
36
+ "postalCode" => "10016",
37
+ "accountId" => 2458392,
38
+ "securityCode" => "719",
39
+ "paymentType" => "Credit Card"
40
+ }
41
+ }]
45
42
  end
46
- should("not be empty"){ !topic.empty? }
47
- should("return code OK"){ topic.resources.first.response.code }.equals(200)
48
- should("return message OK") { topic.resources.first.response.message }.equals("OK")
49
43
  end
50
- end
44
+ should("not be empty"){ !topic.empty? }
45
+ should("return code OK"){ topic.resources.first.response.code }.equals(200)
46
+ should("return message OK") { topic.resources.first.response.message }.equals("OK")
47
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'helper'))
2
+
3
+ context "user log in with raw API" do
4
+ setup do
5
+ CityGrid.login :username => "GARYTEST", :password => 'pppppp'
6
+ end
7
+ should("return an authToken"){ topic.authToken }
8
+ end
9
+
10
+ context "user log in with session" do
11
+ setup do
12
+ CityGrid.session "GARYTEST", "pppppp"
13
+ end
14
+ should("have an auth_token"){ topic.auth_token }
15
+ should("be logged in"){ topic.logged_in? }
16
+ end