itrigga-admin_api_client 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -43,14 +43,29 @@ With the HTTP status_code from the remote call and the exception message.
43
43
  gem install itrigga-admin_api_client
44
44
 
45
45
  Put this in the config/environment.rb file:
46
- config.gem 'itrigga-admin_api_client', :lib => 'trigga/admin_api_client'
46
+ config.gem 'itrigga-admin_api_client', :lib => 'itrigga/admin_api_client'
47
47
 
48
48
  === Rails3:
49
49
  Put this in the Gemfile:
50
- gem 'itrigga-admin_api_client', :lib => 'trigga/admin_api_client'
50
+ gem 'itrigga-admin_api_client', :lib => 'itrigga/admin_api_client'
51
51
 
52
52
  Run 'bundle install'
53
53
 
54
+ == Overriding configuration
55
+
56
+ If the default configuration.yml file is not to your taste it can be overridden by setting ENV['TRIGGA_ADMIN_API_CLIENT_CONFIG_FILE'] to the absolute url of a yml file with the same format to use instead.
57
+ The format needs to be:
58
+ RAILS_ENV:
59
+ admin:
60
+ base_url: xxxxxx
61
+ api:
62
+ base_url: xxxxxx
63
+ search_tracker:
64
+ base_url: xxxxxx
65
+
66
+ Where the base_url for each component is an absolute URL
67
+
68
+
54
69
  == Contributing to itrigga-admin_api_client
55
70
 
56
71
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{itrigga-admin_api_client}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anson Kelly"]
12
- s.date = %q{2011-10-11}
12
+ s.date = %q{2011-10-17}
13
13
  s.description = %q{Wraps API calls to iTrigga applications}
14
14
  s.email = %q{support@itrigga.com}
15
15
  s.extra_rdoc_files = [
@@ -27,11 +27,6 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "configuration.yml",
29
29
  "itrigga-admin_api_client.gemspec",
30
- "lib/trigga/admin_api_client.rb",
31
- "lib/trigga/admin_api_client/admin_api_client.rb",
32
- "lib/trigga/admin_api_client/proxies/admin.rb",
33
- "lib/trigga/admin_api_client/proxies/api.rb",
34
- "lib/trigga/admin_api_client/proxies/search_tracker.rb",
35
30
  "spec/admin_api_client_spec.rb",
36
31
  "spec/proxies/admin_spec.rb",
37
32
  "spec/proxies/api_spec.rb",
@@ -1,21 +1,21 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
 
4
- describe Trigga::AdminApiClient do
4
+ describe Itrigga::AdminApiClient do
5
5
  before do
6
- Trigga.stub!(:add_log_line).and_return(true) # dont need logging info outputted
6
+ Itrigga.stub!(:add_log_line).and_return(true) # dont need logging info outputted
7
7
  end
8
8
 
9
9
  it "should include Trigga::ParamFu" do
10
- Trigga::AdminApiClient.should include Trigga::ParamFu
10
+ Itrigga::AdminApiClient.should include Trigga::ParamFu
11
11
  end
12
12
 
13
13
  it "should include Admin proxy" do
14
- Trigga::AdminApiClient.should include Trigga::AdminApiClient::Proxies::Admin
14
+ Itrigga::AdminApiClient.should include Itrigga::AdminApiClient::Proxies::Admin
15
15
  end
16
16
 
17
17
  it "should include API proxy" do
18
- Trigga::AdminApiClient.should include Trigga::AdminApiClient::Proxies::Api
18
+ Itrigga::AdminApiClient.should include Itrigga::AdminApiClient::Proxies::Api
19
19
  end
20
20
 
21
21
 
@@ -23,39 +23,39 @@ describe Trigga::AdminApiClient do
23
23
  before do
24
24
  TRIGGA_ADMIN_API_CLIENT_CONFIG = {"test" => Hashie::Mash.new(:base_url => "base_url")}
25
25
 
26
- Trigga::AdminApiClient.stub!(:require_param).and_return(true)
27
- Trigga::AdminApiClient.stub!(:build_url).and_return("a url")
26
+ Itrigga::AdminApiClient.stub!(:require_param).and_return(true)
27
+ Itrigga::AdminApiClient.stub!(:build_url).and_return("a url")
28
28
  Itrigga::NetHelper.stub!(:do_get).and_return({:response => "text"}.to_json)
29
29
  @opts = {:api_key => "1234", :abc => 123}
30
30
  end
31
31
 
32
32
  it "should call require_param for api_key" do
33
- Trigga::AdminApiClient.should_receive(:require_param).with(@opts, :api_key).and_return(true)
34
- Trigga::AdminApiClient.make_call("test","stats",@opts)
33
+ Itrigga::AdminApiClient.should_receive(:require_param).with(@opts, :api_key).and_return(true)
34
+ Itrigga::AdminApiClient.make_call("test","stats",@opts)
35
35
  end
36
36
 
37
37
  it "should call build_url with correct params" do
38
- Trigga::AdminApiClient.should_receive(:build_url).with("http://base_url","stats",@opts).and_return("a url")
39
- Trigga::AdminApiClient.make_call("test","stats",@opts)
38
+ Itrigga::AdminApiClient.should_receive(:build_url).with("http://base_url","stats",@opts).and_return("a url")
39
+ Itrigga::AdminApiClient.make_call("test","stats",@opts)
40
40
  end
41
41
 
42
42
  it "should convert the url to absolute" do
43
- Trigga::AdminApiClient.should_receive(:make_absolute_url).with("base_url").and_return("http://base_url")
44
- Trigga::AdminApiClient.make_call("test","stats",@opts)
43
+ Itrigga::AdminApiClient.should_receive(:make_absolute_url).with("base_url").and_return("http://base_url")
44
+ Itrigga::AdminApiClient.make_call("test","stats",@opts)
45
45
  end
46
46
 
47
47
  it "should override the :host" do
48
- Trigga::AdminApiClient.should_receive(:make_absolute_url).with("new_base_url").and_return("http://new_base_url")
49
- Trigga::AdminApiClient.make_call("test","stats",@opts.merge(:host => "new_base_url"))
48
+ Itrigga::AdminApiClient.should_receive(:make_absolute_url).with("new_base_url").and_return("http://new_base_url")
49
+ Itrigga::AdminApiClient.make_call("test","stats",@opts.merge(:host => "new_base_url"))
50
50
  end
51
51
 
52
52
  it "should call net_helper with the url" do
53
53
  Itrigga::NetHelper.should_receive(:do_get).with("a url").and_return({:response => "text"}.to_json)
54
- Trigga::AdminApiClient.make_call("test","stats",@opts)
54
+ Itrigga::AdminApiClient.make_call("test","stats",@opts)
55
55
  end
56
56
 
57
57
  it "should return a mash with the status code" do
58
- Trigga::AdminApiClient.make_call("test","stats",@opts).should == Hashie::Mash.new(:response => "text", :status_code => 200)
58
+ Itrigga::AdminApiClient.make_call("test","stats",@opts).should == Hashie::Mash.new(:response => "text", :status_code => 200)
59
59
  end
60
60
 
61
61
  describe "when an error occurs" do
@@ -64,12 +64,12 @@ describe Trigga::AdminApiClient do
64
64
  end
65
65
 
66
66
  it "should return an error mash when errord out" do
67
- Trigga::AdminApiClient.make_call("test","stats",@opts).should == Hashie::Mash.new(:error => "500 An error", :status_code => 500 )
67
+ Itrigga::AdminApiClient.make_call("test","stats",@opts).should == Hashie::Mash.new(:error => "500 An error", :status_code => 500 )
68
68
  end
69
69
 
70
70
  it "should call status_code_from_error" do
71
- Trigga::AdminApiClient.should_receive(:status_code_from_error).with("500 An error").and_return(500)
72
- Trigga::AdminApiClient.make_call("test","stats",@opts)
71
+ Itrigga::AdminApiClient.should_receive(:status_code_from_error).with("500 An error").and_return(500)
72
+ Itrigga::AdminApiClient.make_call("test","stats",@opts)
73
73
  end
74
74
  end
75
75
  end
@@ -77,11 +77,11 @@ describe Trigga::AdminApiClient do
77
77
 
78
78
  describe "make_endpoint_absolute" do
79
79
  it "should add a /" do
80
- Trigga::AdminApiClient.make_endpoint_absolute("stats").should == "/stats"
80
+ Itrigga::AdminApiClient.make_endpoint_absolute("stats").should == "/stats"
81
81
  end
82
82
 
83
83
  it "should not add an extra /" do
84
- Trigga::AdminApiClient.make_endpoint_absolute("/stats").should == "/stats"
84
+ Itrigga::AdminApiClient.make_endpoint_absolute("/stats").should == "/stats"
85
85
  end
86
86
  end
87
87
 
@@ -89,11 +89,11 @@ describe Trigga::AdminApiClient do
89
89
 
90
90
  describe "build_url" do
91
91
  it "should return the correct url" do
92
- Trigga::AdminApiClient.build_url("http://site.com","stats",:abc => 123).should == "http://site.com/stats.json?abc=123"
92
+ Itrigga::AdminApiClient.build_url("http://site.com","stats",:abc => 123).should == "http://site.com/stats.json?abc=123"
93
93
  end
94
94
 
95
95
  it "should use the given format" do
96
- Trigga::AdminApiClient.build_url("http://site.com","stats",:abc => 123,:format => "xml").should == "http://site.com/stats.xml?abc=123"
96
+ Itrigga::AdminApiClient.build_url("http://site.com","stats",:abc => 123,:format => "xml").should == "http://site.com/stats.xml?abc=123"
97
97
  end
98
98
  end
99
99
 
@@ -101,11 +101,11 @@ describe Trigga::AdminApiClient do
101
101
 
102
102
  describe "status_code_from_error" do
103
103
  it "should return the status code" do
104
- Trigga::AdminApiClient.status_code_from_error("404 I got lost").should == 404
104
+ Itrigga::AdminApiClient.status_code_from_error("404 I got lost").should == 404
105
105
  end
106
106
 
107
107
  it "should return 0 when no status" do
108
- Trigga::AdminApiClient.status_code_from_error("I got lost").should == 0
108
+ Itrigga::AdminApiClient.status_code_from_error("I got lost").should == 0
109
109
  end
110
110
  end
111
111
 
@@ -2,14 +2,14 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'spec_helper'))
2
2
 
3
3
  class AdminApiClientProxyTest
4
4
  include Trigga::ParamFu
5
- include Trigga::AdminApiClient::Proxies::Admin
5
+ include Itrigga::AdminApiClient::Proxies::Admin
6
6
  end
7
7
 
8
- describe Trigga::AdminApiClient::Proxies::Admin do
8
+ describe Itrigga::AdminApiClient::Proxies::Admin do
9
9
  before do
10
10
  AdminApiClientProxyTest.stub!(:require_one_of).and_return(true)
11
11
  AdminApiClientProxyTest.stub!(:require_param).and_return(true)
12
- Trigga::AdminApiClient.stub!(:make_call).and_return(true)
12
+ Itrigga::AdminApiClient.stub!(:make_call).and_return(true)
13
13
  @opts = {:abc => 123, :api_key => "blah"}
14
14
  end
15
15
 
@@ -19,7 +19,7 @@ describe Trigga::AdminApiClient::Proxies::Admin do
19
19
  end
20
20
 
21
21
  it "should call make_call" do
22
- Trigga::AdminApiClient.should_receive(:make_call).with("admin","stats",@opts)
22
+ Itrigga::AdminApiClient.should_receive(:make_call).with("admin","stats",@opts)
23
23
  AdminApiClientProxyTest.new.get_stats @opts
24
24
  end
25
25
  end
@@ -27,7 +27,7 @@ describe Trigga::AdminApiClient::Proxies::Admin do
27
27
 
28
28
  describe "get_clients" do
29
29
  it "should call make_call" do
30
- Trigga::AdminApiClient.should_receive(:make_call).with("admin","clients",@opts)
30
+ Itrigga::AdminApiClient.should_receive(:make_call).with("admin","clients",@opts)
31
31
  AdminApiClientProxyTest.new.get_clients @opts
32
32
  end
33
33
  end
@@ -44,7 +44,7 @@ describe Trigga::AdminApiClient::Proxies::Admin do
44
44
  end
45
45
 
46
46
  it "should call make_call" do
47
- Trigga::AdminApiClient.should_receive(:make_call).with("admin","clients/42",@opts)
47
+ Itrigga::AdminApiClient.should_receive(:make_call).with("admin","clients/42",@opts)
48
48
  AdminApiClientProxyTest.new.get_client @opts
49
49
  end
50
50
  end
@@ -2,14 +2,14 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'spec_helper'))
2
2
 
3
3
  class ApiApiClientProxyTest
4
4
  include Trigga::ParamFu
5
- include Trigga::AdminApiClient::Proxies::Api
5
+ include Itrigga::AdminApiClient::Proxies::Api
6
6
  end
7
7
 
8
- describe Trigga::AdminApiClient::Proxies::Api do
8
+ describe Itrigga::AdminApiClient::Proxies::Api do
9
9
  before do
10
10
  ApiApiClientProxyTest.stub!(:require_one_of).and_return(true)
11
11
  ApiApiClientProxyTest.stub!(:require_param).and_return(true)
12
- Trigga::AdminApiClient.stub!(:make_call).and_return(true)
12
+ Itrigga::AdminApiClient.stub!(:make_call).and_return(true)
13
13
  @opts = {:abc => 123, :api_key => "blah"}
14
14
  end
15
15
 
@@ -28,7 +28,7 @@ describe Trigga::AdminApiClient::Proxies::Api do
28
28
  end
29
29
 
30
30
  it "should call make_call filtering out bad params" do
31
- Trigga::AdminApiClient.should_receive(:make_call).with("api","endpoint",{:api_key => "blah"})
31
+ Itrigga::AdminApiClient.should_receive(:make_call).with("api","endpoint",{:api_key => "blah"})
32
32
  ApiApiClientProxyTest.new.send("make_api_call","endpoint",@opts)
33
33
  end
34
34
  end
@@ -2,8 +2,8 @@ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'spec_helper'))
2
2
 
3
3
  class SearchTrackerApiClientProxyTest
4
4
  include Trigga::ParamFu
5
- include Trigga::AdminApiClient::Proxies::SearchTracker
5
+ include Itrigga::AdminApiClient::Proxies::SearchTracker
6
6
  end
7
7
 
8
- describe Trigga::AdminApiClient::Proxies::SearchTracker do
8
+ describe Itrigga::AdminApiClient::Proxies::SearchTracker do
9
9
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
 
4
- require 'trigga/admin_api_client'
4
+ require 'itrigga/admin_api_client'
5
5
 
6
6
  # Requires supporting files with custom matchers and macros, etc,
7
7
  # in ./support/ and its subdirectories.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itrigga-admin_api_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Anson Kelly
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-11 00:00:00 +01:00
18
+ date: 2011-10-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -256,11 +256,6 @@ files:
256
256
  - VERSION
257
257
  - configuration.yml
258
258
  - itrigga-admin_api_client.gemspec
259
- - lib/trigga/admin_api_client.rb
260
- - lib/trigga/admin_api_client/admin_api_client.rb
261
- - lib/trigga/admin_api_client/proxies/admin.rb
262
- - lib/trigga/admin_api_client/proxies/api.rb
263
- - lib/trigga/admin_api_client/proxies/search_tracker.rb
264
259
  - spec/admin_api_client_spec.rb
265
260
  - spec/proxies/admin_spec.rb
266
261
  - spec/proxies/api_spec.rb
@@ -1,31 +0,0 @@
1
- # allow this to be used outside of full Rails init
2
- this_dir = File.dirname(__FILE__)
3
- $: << this_dir unless $:.include?(this_dir)
4
-
5
- #require 'faster_csv'
6
- require 'yaml'
7
- require 'hashie'
8
- require 'core_ext'
9
- require 'trigga/param_fu'
10
- require 'net_helper'
11
-
12
- #require 'trigga/param_fu'
13
- Dir[File.join(File.dirname(File.expand_path(__FILE__)),"admin_api_client","proxies","*.rb")].each {|f| require f }
14
- Dir[File.join(File.dirname(File.expand_path(__FILE__)),"admin_api_client","*.rb")].each {|f| require f }
15
-
16
- # load configuration
17
- unless defined? RAILS_ENV
18
- RAILS_ENV = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development"
19
- end
20
-
21
- Trigga.add_log_line("", true)
22
- Trigga.add_log_line(" iTrigga Admin Client API")
23
- Trigga.add_log_line("", true)
24
-
25
- begin
26
- plugin_configuration_file = File.join(File.dirname(File.expand_path(__FILE__)),"..","..","configuration.yml")
27
- TRIGGA_ADMIN_API_CLIENT_CONFIG = Hashie::Mash.new(YAML.load_file(plugin_configuration_file)[RAILS_ENV])
28
- rescue Exception => e
29
- Trigga.add_log_line("...disabled => Unable to load Admin Client API configuration from #{plugin_configuration_file}.\n")
30
- Trigga.add_log_line("Exception: #{e.message}")
31
- end
@@ -1,86 +0,0 @@
1
- module Trigga
2
- module AdminApiClient
3
- include Trigga::ParamFu
4
- include Trigga::AdminApiClient::Proxies::Admin
5
- include Trigga::AdminApiClient::Proxies::Api
6
- include Trigga::AdminApiClient::Proxies::SearchTracker
7
-
8
- private
9
-
10
- def self.make_call(module_name, endpoint, opts = {})
11
- require_param(opts, :api_key)
12
-
13
- host = make_absolute_url( opts[:host] || TRIGGA_ADMIN_API_CLIENT_CONFIG[module_name].base_url )
14
-
15
- begin
16
- url = build_url(host,endpoint,opts)
17
- Trigga.add_log_line("[API Client] - #{url}")
18
-
19
- response = JSON.parse(Itrigga::NetHelper.do_get(url))
20
- ::Hashie::Mash.new(response.kind_of?(Array) ? default_response : response.merge(default_response) )
21
-
22
- rescue Exception => e
23
- Trigga.add_log_line "[API Client Error] - #{e.message}\n#{e.backtrace.join('\n')}" if RAILS_ENV == "development"
24
- ::Hashie::Mash.new(:error => e.message, :status_code => status_code_from_error(e.message))
25
- end
26
- end
27
-
28
- def self.default_response
29
- {:status_code => 200}
30
- end
31
-
32
- def self.make_endpoint_absolute(endpoint)
33
- endpoint.to_s.match(/^\/{1}.*/) ? endpoint : "/#{endpoint}"
34
- end
35
-
36
- def self.make_absolute_url(url)
37
- url.to_s.match(/^https?:\/\//) ? url : "http://#{url}"
38
- end
39
-
40
- def self.build_url(url, endpoint, h = {})
41
- # default format to json
42
- format = h[:format] || "json"
43
- h.delete :format
44
-
45
- params = h.map { |k, v| "#{k}=#{v}" }.join("&")
46
- "#{url}#{make_endpoint_absolute(endpoint)}.#{format}#{params.empty? ? '' : '?' + params}"
47
- end
48
-
49
- # get the status code from the error message
50
- # eg "404 Not Found"
51
- def self.status_code_from_error(error)
52
- code = error.match(/^(\d{3} )/)
53
- if code
54
- code.to_s.to_i
55
- else
56
- 0
57
- end
58
- end
59
-
60
- end
61
-
62
- # ==============================================================================================================================
63
- # Prints a debugging info line into the log...
64
- # ==============================================================================================================================
65
-
66
- def self.add_log_line(line, add_padding = false)
67
- is_terminal = false
68
- begin
69
- @terminal_width ||= `stty size`.split.map { |x| x.to_i }.reverse[0]
70
- is_terminal = true
71
- rescue Exception => e
72
- # not running in terminal``
73
- end
74
-
75
- if add_padding and is_terminal and !@terminal_width.nil?
76
- puts "#{line.ljust(@terminal_width - line.length, "=")}\n"
77
- else
78
- if defined?(Rails.logger)
79
- Rails.logger.info line
80
- else
81
- puts line
82
- end
83
- end
84
- end
85
-
86
- end
@@ -1,26 +0,0 @@
1
- module Trigga
2
- module AdminApiClient
3
- module Proxies
4
- module Admin
5
-
6
- def self.included(base)
7
- base.send("extend",self)
8
- end
9
-
10
- def get_stats( opts = {})
11
- Trigga::AdminApiClient.make_call "admin", "stats", opts
12
- end
13
-
14
- def get_clients(opts = {})
15
- Trigga::AdminApiClient.make_call "admin", "clients", opts
16
- end
17
-
18
- def get_client(opts = {})
19
- require_param(opts, :client_id)
20
- Trigga::AdminApiClient.make_call "admin", "clients/#{opts[:client_id]}", opts
21
- end
22
-
23
- end
24
- end
25
- end
26
- end
@@ -1,52 +0,0 @@
1
- module Trigga
2
- module AdminApiClient
3
- module Proxies
4
- module Api
5
-
6
- def self.included(base)
7
- base.send("extend",self)
8
- end
9
-
10
- private
11
-
12
- def common_params
13
- [:page, :per_page, :max_tags, :site_key, :api_key]
14
- end
15
-
16
- def make_api_call(endpoint, opts = {})
17
- require_one_of( opts, :site_key, :site_id )
18
- Trigga::AdminApiClient.make_call("api", endpoint, opts.reject{|k,v| !common_params.include?(k.to_sym) } )
19
- end
20
-
21
- public
22
-
23
- def get_channels(opts)
24
- make_api_call("channels", opts )
25
- end
26
-
27
- def get_channel_items( opts )
28
- require_param( opts, :channel_id )
29
- make_api_call("channels/#{opts[:channel_id]}", opts )
30
- end
31
-
32
- def get_sources( opts )
33
- make_api_call('sources', opts)
34
- end
35
-
36
- def get_item_tags( opts )
37
- make_api_call('item_tags', opts)
38
- end
39
-
40
- def get_latest_items( opts )
41
- make_api_call('items', opts)
42
- end
43
-
44
- def get_item_details( opts )
45
- require_param( opts, :item_id )
46
- make_api_call("items/#{opts[:item_id]}", opts)
47
- end
48
-
49
- end
50
- end
51
- end
52
- end
@@ -1,13 +0,0 @@
1
- module Trigga
2
- module AdminApiClient
3
- module Proxies
4
- module SearchTracker
5
-
6
- def self.included(base)
7
- base.send("extend",self)
8
- end
9
-
10
- end
11
- end
12
- end
13
- end