appnexusapi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,13 +24,13 @@ Establish a connection:
24
24
  # optionally pass a uri for the staging site
25
25
  # defaults to "http://api.adnxs.com/"
26
26
  # uri => "http://api.sand-08.adnxs.net",
27
- username => 'username',
28
- password => 'password'
27
+ "username" => 'username',
28
+ "password" => 'password'
29
29
  })
30
30
 
31
31
  Use a Service:
32
32
 
33
- member_service = AppnexusApi::MemberService(connection)
33
+ member_service = AppnexusApi::MemberService.new(connection)
34
34
  # get always returns an array of results
35
35
  # and defaults "num_elements" to 100 and "start_element" to 0
36
36
  # and returns an AppnexusApi::Resource object which is a wrapper around the JSON
@@ -0,0 +1,2 @@
1
+ class AppnexusApi::LineItemResource < AppnexusApi::Resource
2
+ end
@@ -0,0 +1,2 @@
1
+ class AppnexusApi::LineItemService < AppnexusApi::Service
2
+ end
@@ -5,8 +5,10 @@ class AppnexusApi::Service
5
5
  end
6
6
 
7
7
  def name
8
- str = self.class.name.split("::").last.gsub("Service", "")
9
- str.gsub(/(.)([A-Z])/, '\1_\2').downcase
8
+ @name ||= begin
9
+ str = self.class.name.split("::").last.gsub("Service", "")
10
+ str.gsub(/(.)([A-Z])/, '\1_\2').downcase
11
+ end
10
12
  end
11
13
 
12
14
  def plural_name
@@ -14,26 +16,41 @@ class AppnexusApi::Service
14
16
  end
15
17
 
16
18
  def resource_class
17
- resource_name = name.capitalize.gsub(/(_(.))/) { |c| $2.upcase }
18
- AppnexusApi.const_get(resource_name + "Resource")
19
+ @resource_class ||= begin
20
+ resource_name = name.capitalize.gsub(/(_(.))/) { |c| $2.upcase }
21
+ AppnexusApi.const_get(resource_name + "Resource")
22
+ end
19
23
  end
20
-
21
- def uri_suffix
24
+
25
+ def uri_name
22
26
  name.gsub('_', '-')
23
27
  end
28
+
29
+ def plural_uri_name
30
+ uri_name + 's'
31
+ end
32
+
33
+ def uri_suffix
34
+ uri_name
35
+ end
24
36
 
25
37
  def get(params={})
38
+ return_response = params.delete(:return_response) || false
26
39
  params = {
27
40
  "num_elements" => 100,
28
41
  "start_element" => 0
29
42
  }.merge(params)
30
43
  response = @connection.get(uri_suffix, params)
31
- if response.has_key?(plural_name)
32
- response[plural_name].map do |json|
44
+ if return_response
45
+ response
46
+ elsif response.has_key?(plural_name) || response.has_key?(plural_uri_name)
47
+ key = response.has_key?(plural_name) ? plural_name : plural_uri_name
48
+ response[key].map do |json|
33
49
  resource_class.new(json, self)
34
50
  end
35
- elsif response.has_key?(name)
36
- [resource_class.new(response[name], self)]
51
+ elsif response.has_key?(name) || response.has_key?(uri_name)
52
+ key = response.has_key?(name) ? name : uri_name
53
+ [resource_class.new(response[key], self)]
37
54
  end
38
55
  end
39
56
 
@@ -1,3 +1,3 @@
1
1
  module AppnexusApi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appnexusapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-11-01 00:00:00.000000000Z
12
+ date: 2013-02-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: &2153678980 !ruby/object:Gem::Requirement
16
+ requirement: &2155055900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.7.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153678980
24
+ version_requirements: *2155055900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multi_json
27
- requirement: &2153677660 !ruby/object:Gem::Requirement
27
+ requirement: &2155052140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153677660
35
+ version_requirements: *2155052140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2153676440 !ruby/object:Gem::Requirement
38
+ requirement: &2155051680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.2.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153676440
46
+ version_requirements: *2155051680
47
47
  description: ''
48
48
  email:
49
49
  - brandon.aaron@gmail.com
@@ -89,6 +89,8 @@ files:
89
89
  - lib/appnexusapi/inventory_source_service.rb
90
90
  - lib/appnexusapi/language_resource.rb
91
91
  - lib/appnexusapi/language_service.rb
92
+ - lib/appnexusapi/line_item_resource.rb
93
+ - lib/appnexusapi/line_item_service.rb
92
94
  - lib/appnexusapi/member_resource.rb
93
95
  - lib/appnexusapi/member_service.rb
94
96
  - lib/appnexusapi/operating_system_service.rb
@@ -130,3 +132,4 @@ signing_key:
130
132
  specification_version: 3
131
133
  summary: Unofficial Ruby API Wrapper for Appnexus
132
134
  test_files: []
135
+ has_rdoc: