Class: CityGrid::API
- Inherits:
-
Object
show all
- Includes:
- CityGridExceptions, HTTParty
- Defined in:
- lib/citygrid/api.rb,
lib/citygrid/api/ads.rb,
lib/citygrid/api/content.rb,
lib/citygrid/api/mutable.rb,
lib/citygrid/api/accounts.rb,
lib/citygrid/api/response.rb,
lib/citygrid/api/ads/custom.rb,
lib/citygrid/api/searchable.rb,
lib/citygrid/api/advertising.rb,
lib/citygrid/api/accounts/user.rb,
lib/citygrid/api/accounts/login.rb,
lib/citygrid/api/content/offers.rb,
lib/citygrid/api/content/places.rb,
lib/citygrid/api/content/reviews.rb,
lib/citygrid/api/accounts/account.rb,
lib/citygrid/api/content/response.rb,
lib/citygrid/api/advertising/image.rb,
lib/citygrid/api/advertising/budget.rb,
lib/citygrid/api/advertising/offers.rb,
lib/citygrid/api/advertising/places.rb,
lib/citygrid/api/advertising/billing.rb,
lib/citygrid/api/advertising/ad_group.rb,
lib/citygrid/api/advertising/campaign.rb,
lib/citygrid/api/advertising/category.rb,
lib/citygrid/api/advertising/places_get.rb,
lib/citygrid/api/advertising/ad_group_ad.rb,
lib/citygrid/api/advertising/call_detail.rb,
lib/citygrid/api/advertising/geolocation.rb,
lib/citygrid/api/advertising/performance.rb,
lib/citygrid/api/advertising/ad_group_geo.rb,
lib/citygrid/api/content/profile_internal.rb,
lib/citygrid/api/accounts/method_of_payment.rb,
lib/citygrid/api/accounts/temp_impersonation.rb,
lib/citygrid/api/advertising/account_manager.rb,
lib/citygrid/api/advertising/ad_group_criterion.rb,
lib/citygrid/api/advertising/campaign_promotions.rb,
lib/citygrid/api/advertising/ad_group_call_detail.rb
Defined Under Namespace
Modules: Mutable, Searchable
Classes: Accounts, Ads, Advertising, ConfigurationError, Content, MUSHPendingChanges, Response
Constant Summary
collapse
{
"Accept" => "application/json",
"Content-Type" => "Application/JSON"}
- DEFAULT_ACTION_OPTIONS =
{
:auth_token => false,
:format => true,
:publisher => false,
:client_ip => false
}
- AdCenter =
CityGrid::API::Advertising
Class Method Summary
collapse
appropriate_error
Class Method Details
.define_action(name, method, action, define_options = {}) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/citygrid/api.rb', line 24
def define_action name, method, action, define_options = {}
define_options = DEFAULT_ACTION_OPTIONS.merge define_options
define_singleton_method name.intern do |*args|
options = args.first.clone || {}
params = {}
token = options.delete :token
= API::DEFAULT_HEADERS.clone
.merge! "authToken" => token if define_options[:auth_token] && token
options.merge! "format" => "json" if define_options[:format]
options.merge! "publisher" => CityGrid.publisher if define_options[:publisher]
options.merge! "client_ip" => "192.168.0.1" if define_options[:client_ip]
params[:headers] =
case method
when :post
params[:body] = options.to_json
when :get
params[:query] = options
end
request_and_handle method.intern, "#{endpoint}/#{action}", params
end
end
|
.endpoint(val = nil) ⇒ Object
60
61
62
63
|
# File 'lib/citygrid/api.rb', line 60
def endpoint val = nil
return @endpoint unless val
@endpoint = val
end
|
.newendpoint(val = nil) ⇒ Object
65
66
67
68
|
# File 'lib/citygrid/api.rb', line 65
def newendpoint val = nil
return @newendpoint unless val
@newendpoint = val
end
|
.request(options = {}) ⇒ Object
70
71
72
73
74
|
# File 'lib/citygrid/api.rb', line 70
def request options = {}
method = (options.delete(:method) || :get).to_sym
query = options.merge :format => :json
request_and_handle method, endpoint, :query => query
end
|