lib/rocketfuel_api/service.rb in rocketfuel_api-0.1.1 vs lib/rocketfuel_api/service.rb in rocketfuel_api-0.1.2
- old
+ new
@@ -17,16 +17,17 @@
str = self.class.name.split('::').last
str.gsub(/(.)([A-Z])/, '\1_\2').downcase
end
end
- def plural_name
- name + 's'
- end
-
def uri_suffix
- plural_name
+ file_path = RocketfuelApi.root.join('lib', 'config', 'endpoints_for_services.yaml')
+ endpoints = YAML.load_file(file_path)
+ endpoint = endpoints['service'][name]
+
+ endpoint || raise(RocketfuelApi::NotImplemented,
+ format('No endpoint for service %s available.', name))
end
def get(id, params = {})
params = params.merge("#{name}_id" => id)
@@ -40,12 +41,10 @@
parse_response(response)
end
def create(route_params = {}, body = {})
- raise(RocketfuelApi::NotImplemented, 'Service is read-only.') if @read_only
-
body = { uri_name => body }
route = @connection.build_url(uri_suffix, route_params)
response = @connection.post(route, body)
if response.status != 200
@@ -54,12 +53,10 @@
parse_response(response.body)
end
def update(id, route_params = {}, body = {})
- raise(AppnexusApi::NotImplemented, 'Service is read-only.') if @read_only
-
body = { uri_name => body }
route = @connection.build_url(uri_suffix, route_params.merge('id' => id))
response = @connection.put(route, body)
if response.status != 200
@@ -76,9 +73,9 @@
resource_class.new(json, self)
end
when Hash
resource_class.new(response, self)
else
- raise format("Can't parse response, it's a %s", response.class)
+ raise(RocketfuelApi::NotImplemented, format('Unknown response type %s.', response.class))
end
end
end