itrigga-admin_api_client 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "itrigga-core_ext"
9
+ gem "itrigga-param_fu"
10
+ gem "itrigga-net_helper"
11
+ gem "hashie"
12
+
13
+ group :development do
14
+ gem "rspec", "1.3.0"
15
+ gem "rspec-rails", "1.3.2"
16
+ gem "bundler", "~> 1.0.0"
17
+ gem "jeweler", "~> 1.6.4"
18
+ gem "rcov", ">= 0"
19
+ gem "fastercsv"
20
+ gem "hpricot"
21
+ gem "json_pure"
22
+ end
23
+
24
+ group :test do
25
+ gem "rspec", "1.3.0"
26
+ gem "rspec-rails", "1.3.2"
27
+ gem "bundler", "~> 1.0.0"
28
+ gem "rcov", ">= 0"
29
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ fastercsv (1.5.4)
5
+ git (1.2.5)
6
+ hashie (1.1.0)
7
+ hpricot (0.8.4)
8
+ itrigga-core_ext (0.2.2)
9
+ itrigga-net_helper (0.0.3)
10
+ itrigga-param_fu (0.0.1)
11
+ jeweler (1.6.4)
12
+ bundler (~> 1.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ json_pure (1.5.3)
16
+ rack (1.1.0)
17
+ rake (0.8.7)
18
+ rcov (0.9.9)
19
+ rspec (1.3.0)
20
+ rspec-rails (1.3.2)
21
+ rack (>= 1.0.0)
22
+ rspec (>= 1.3.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ fastercsv
30
+ hashie
31
+ hpricot
32
+ itrigga-core_ext
33
+ itrigga-net_helper
34
+ itrigga-param_fu
35
+ jeweler (~> 1.6.4)
36
+ json_pure
37
+ rcov
38
+ rspec (= 1.3.0)
39
+ rspec-rails (= 1.3.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Anson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,68 @@
1
+ = itrigga-admin_api_client
2
+
3
+ Wraps API calls to iTrigga Applications
4
+
5
+ Each API call requires an :api_key.
6
+ All calls to the api module also require either a :site or :site_id
7
+
8
+ Other calls many require different params. If these are not provided then an exception is raised.
9
+
10
+ Example:
11
+ Trigga::AdminApiClient.get_stats(:api_key => "fDhtXwx8_Mpx9evOsxXf")
12
+
13
+ Hits this endpoint:
14
+ http://localhost:3000/admin/stats.json?api_key=fDhtXwx8_Mpx9evOsxXf
15
+
16
+ And returns:
17
+ {
18
+ "api_calls" => 149,
19
+ "max_item_id" => 218,
20
+ "max_source_id" => 10,
21
+ "item_counts" => {
22
+ "aggregated" => 1,
23
+ "editorial" => 22
24
+ },
25
+ "status_code" => 200,
26
+ "max_scheduled_job_id" => 1252
27
+ }
28
+
29
+ Each call will return results as a Mash.
30
+
31
+ Each call will return a :status_code (normally 200 for when it went ok, else an error code eg 500)
32
+
33
+ If an error occurs a Mash will be returned like:
34
+ {
35
+ "status_code" => 500,
36
+ "error" => "500 Error description goes in here"
37
+ }
38
+ With the HTTP status_code from the remote call and the exception message.
39
+
40
+ == Installation
41
+
42
+ === Rails2:
43
+ gem install itrigga-admin_api_client
44
+
45
+ Put this in the config/environment.rb file:
46
+ config.gem 'itrigga-admin_api_client', :lib => 'trigga/admin_api_client'
47
+
48
+ === Rails3:
49
+ Put this in the Gemfile:
50
+ gem 'itrigga-admin_api_client', :lib => 'trigga/admin_api_client'
51
+
52
+ Run 'bundle install'
53
+
54
+ == Contributing to itrigga-admin_api_client
55
+
56
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
57
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
58
+ * Fork the project
59
+ * Start a feature/bugfix branch
60
+ * Commit and push until you are happy with your contribution
61
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
62
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
63
+
64
+ == Copyright
65
+
66
+ Copyright (c) 2011 Anson. See LICENSE.txt for
67
+ further details.
68
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "itrigga-admin_api_client"
18
+ gem.homepage = "http://rubygems.org/itrigga-admin_api_client"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Wraps API calls to iTrigga applications}
21
+ gem.description = %Q{Wraps API calls to iTrigga applications}
22
+ gem.email = "support@itrigga.com"
23
+ gem.authors = ["Anson Kelly"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency "itrigga-core_ext"
26
+ gem.add_dependency "itrigga-param_fu"
27
+ gem.add_dependency "itrigga-net_helper"
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'spec/version'
32
+ require 'spec/rake/spectask'
33
+ require 'spec/ruby'
34
+
35
+ Spec::Rake::SpecTask.new(:spec) do |spec|
36
+ RAILS_ENV = "test"
37
+ spec.spec_files = FileList['spec/**/*_spec.rb']
38
+ spec.spec_opts = ['--options', 'spec/spec.opts']
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ desc "Run all specs with rcov"
44
+ Spec::Rake::SpecTask.new(:rcov) do |t|
45
+ t.spec_files = FileList['spec/**/*_spec.rb']
46
+ t.spec_opts = ['--options', 'spec/spec.opts']
47
+ t.rcov = true
48
+ t.rcov_dir = 'coverage'
49
+ t.rcov_opts = ['--exclude', "features,kernel,load-diff-lcs\.rb,instance_exec\.rb,lib/spec.rb,lib/spec/runner.rb,^spec/*,bin/spec,examples,/gems,/Library/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
50
+ t.rcov_opts << '--sort coverage --text-summary --aggregate coverage.data'
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/configuration.yml ADDED
@@ -0,0 +1,23 @@
1
+ development:
2
+ admin:
3
+ base_url: http://localhost:3000/admin
4
+ search_tracker:
5
+ base_url: http://localhost:4000
6
+ api:
7
+ base_url: http://localhost:3000/api/v1
8
+
9
+ staging_ec2:
10
+ admin:
11
+ base_url: http://localhost:3000/admin
12
+ search_tracker:
13
+ base_url: http://localhost:4000
14
+ api:
15
+ base_url: http://localhost:3000/api/v1
16
+
17
+ production_ec2:
18
+ admin:
19
+ base_url: http://admin.itrigga.com/admin
20
+ search_tracker:
21
+ base_url: http://searchtracker.itrigga.com
22
+ api:
23
+ base_url: http://api.itrigga.com/api/v1
@@ -0,0 +1,82 @@
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 = Itrigga::NetHelper.do_get(url)
20
+ ::Hashie::Mash.new(JSON.parse(response).merge(:status_code => 200))
21
+
22
+ rescue Exception => e
23
+ Trigga.add_log_line "[API Client Error] - #{e.message}\n#{e.backtrace.join('\n')}"
24
+ ::Hashie::Mash.new(:error => e.message, :status_code => status_code_from_error(e.message))
25
+ end
26
+ end
27
+
28
+ def self.make_endpoint_absolute(endpoint)
29
+ endpoint.to_s.match(/^\/{1}.*/) ? endpoint : "/#{endpoint}"
30
+ end
31
+
32
+ def self.make_absolute_url(url)
33
+ url.to_s.match(/^https?:\/\//) ? url : "http://#{url}"
34
+ end
35
+
36
+ def self.build_url(url, endpoint, h = {})
37
+ # default format to json
38
+ format = h[:format] || "json"
39
+ h.delete :format
40
+
41
+ params = h.map { |k, v| "#{k}=#{v}" }.join("&")
42
+ "#{url}#{make_endpoint_absolute(endpoint)}.#{format}#{params.empty? ? '' : '?' + params}"
43
+ end
44
+
45
+ # get the status code from the error message
46
+ # eg "404 Not Found"
47
+ def self.status_code_from_error(error)
48
+ code = error.match(/^(\d{3} )/)
49
+ if code
50
+ code.to_s.to_i
51
+ else
52
+ 0
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ # ==============================================================================================================================
59
+ # Prints a debugging info line into the log...
60
+ # ==============================================================================================================================
61
+
62
+ def self.add_log_line(line, add_padding = false)
63
+ is_terminal = false
64
+ begin
65
+ @terminal_width ||= `stty size`.split.map { |x| x.to_i }.reverse[0]
66
+ is_terminal = true
67
+ rescue Exception => e
68
+ # not running in terminal``
69
+ end
70
+
71
+ if add_padding and is_terminal and !@terminal_width.nil?
72
+ puts "#{line.ljust(@terminal_width - line.length, "=")}\n"
73
+ else
74
+ if defined?(Rails.logger)
75
+ Rails.logger.info line
76
+ else
77
+ puts line
78
+ end
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,18 @@
1
+ module Trigga
2
+ module AdminApiClient
3
+ module Proxies
4
+ module Admin
5
+
6
+ def self.included(base)
7
+ base.send("extend",self)
8
+ base.send(:include, Trigga::ParamFu)
9
+ end
10
+
11
+ def get_stats( opts )
12
+ Trigga::AdminApiClient.make_call "admin", "stats", opts
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,53 @@
1
+ module Trigga
2
+ module AdminApiClient
3
+ module Proxies
4
+ module Api
5
+
6
+ def self.included(base)
7
+ base.send("extend",self)
8
+ base.send(:include, Trigga::ParamFu)
9
+ end
10
+
11
+ private
12
+
13
+ def common_params
14
+ [:page, :per_page, :max_tags, :site_key, :api_key]
15
+ end
16
+
17
+ def make_api_call(endpoint, opts = {})
18
+ require_one_of( opts, :site_key, :site_id )
19
+ Trigga::AdminApiClient.make_call("api", endpoint, opts.reject{|k,v| !common_params.include?(k.to_sym) } )
20
+ end
21
+
22
+ public
23
+
24
+ def get_channels(opts)
25
+ make_api_call("channels", opts )
26
+ end
27
+
28
+ def get_channel_items( opts )
29
+ require_param( opts, :channel_id )
30
+ make_api_call("channels/#{opts[:channel_id]}", opts )
31
+ end
32
+
33
+ def get_sources( opts )
34
+ make_api_call('sources', opts)
35
+ end
36
+
37
+ def get_item_tags( opts )
38
+ make_api_call('item_tags', opts)
39
+ end
40
+
41
+ def get_latest_items( opts )
42
+ make_api_call('items', opts)
43
+ end
44
+
45
+ def get_item_details( opts )
46
+ require_param( opts, :item_id )
47
+ make_api_call("items/#{opts[:item_id]}", opts)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ module Trigga
2
+ module AdminApiClient
3
+ module Proxies
4
+ module SearchTracker
5
+
6
+ def self.included(base)
7
+ base.send("extend",self)
8
+ base.send(:include, Trigga::ParamFu)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,111 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+
4
+ describe Trigga::AdminApiClient do
5
+ before do
6
+ Trigga.stub!(:add_log_line).and_return(true) # dont need logging info outputted
7
+ end
8
+
9
+ it "should include Trigga::ParamFu" do
10
+ Trigga::AdminApiClient.should include Trigga::ParamFu
11
+ end
12
+
13
+ it "should include Admin proxy" do
14
+ Trigga::AdminApiClient.should include Trigga::AdminApiClient::Proxies::Admin
15
+ end
16
+
17
+ it "should include API proxy" do
18
+ Trigga::AdminApiClient.should include Trigga::AdminApiClient::Proxies::Api
19
+ end
20
+
21
+
22
+ describe "make_call" do
23
+ before do
24
+ TRIGGA_ADMIN_API_CLIENT_CONFIG = {"test" => Hashie::Mash.new(:base_url => "base_url")}
25
+ Trigga::AdminApiClient.stub!(:require_param).and_return(true)
26
+ Trigga::AdminApiClient.stub!(:build_url).and_return("a url")
27
+ Itrigga::NetHelper.stub!(:do_get).and_return({:response => "text"}.to_json)
28
+ @opts = {:api_key => "1234", :abc => 123}
29
+ end
30
+
31
+ it "should call require_param for api_key" do
32
+ Trigga::AdminApiClient.should_receive(:require_param).with(@opts, :api_key).and_return(true)
33
+ Trigga::AdminApiClient.make_call("test","stats",@opts)
34
+ end
35
+
36
+ it "should call build_url with correct params" do
37
+ Trigga::AdminApiClient.should_receive(:build_url).with("http://base_url","stats",@opts).and_return("a url")
38
+ Trigga::AdminApiClient.make_call("test","stats",@opts)
39
+ end
40
+
41
+ it "should convert the url to absolute" do
42
+ Trigga::AdminApiClient.should_receive(:make_absolute_url).with("base_url").and_return("http://base_url")
43
+ Trigga::AdminApiClient.make_call("test","stats",@opts)
44
+ end
45
+
46
+ it "should override the :host" do
47
+ Trigga::AdminApiClient.should_receive(:make_absolute_url).with("new_base_url").and_return("http://new_base_url")
48
+ Trigga::AdminApiClient.make_call("test","stats",@opts.merge(:host => "new_base_url"))
49
+ end
50
+
51
+ it "should call net_helper with the url" do
52
+ Itrigga::NetHelper.should_receive(:do_get).with("a url").and_return({:response => "text"}.to_json)
53
+ Trigga::AdminApiClient.make_call("test","stats",@opts)
54
+ end
55
+
56
+ it "should return a mash with the status code" do
57
+ Trigga::AdminApiClient.make_call("test","stats",@opts).should == Hashie::Mash.new(:response => "text", :status_code => 200)
58
+ end
59
+
60
+ describe "when an error occurs" do
61
+ before do
62
+ Itrigga::NetHelper.stub!(:do_get).and_raise("500 An error")
63
+ end
64
+
65
+ it "should return an error mash when errord out" do
66
+ Trigga::AdminApiClient.make_call("test","stats",@opts).should == Hashie::Mash.new(:error => "500 An error", :status_code => 500 )
67
+ end
68
+
69
+ it "should call status_code_from_error" do
70
+ Trigga::AdminApiClient.should_receive(:status_code_from_error).with("500 An error").and_return(500)
71
+ Trigga::AdminApiClient.make_call("test","stats",@opts)
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+ describe "make_endpoint_absolute" do
78
+ it "should add a /" do
79
+ Trigga::AdminApiClient.make_endpoint_absolute("stats").should == "/stats"
80
+ end
81
+
82
+ it "should not add an extra /" do
83
+ Trigga::AdminApiClient.make_endpoint_absolute("/stats").should == "/stats"
84
+ end
85
+ end
86
+
87
+
88
+
89
+ describe "build_url" do
90
+ it "should return the correct url" do
91
+ Trigga::AdminApiClient.build_url("http://site.com","stats",:abc => 123).should == "http://site.com/stats.json?abc=123"
92
+ end
93
+
94
+ it "should use the given format" do
95
+ Trigga::AdminApiClient.build_url("http://site.com","stats",:abc => 123,:format => "xml").should == "http://site.com/stats.xml?abc=123"
96
+ end
97
+ end
98
+
99
+
100
+
101
+ describe "status_code_from_error" do
102
+ it "should return the status code" do
103
+ Trigga::AdminApiClient.status_code_from_error("404 I got lost").should == 404
104
+ end
105
+
106
+ it "should return 0 when no status" do
107
+ Trigga::AdminApiClient.status_code_from_error("I got lost").should == 0
108
+ end
109
+ end
110
+
111
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'spec_helper'))
2
+
3
+ class AdminApiClientProxyTest
4
+ include Trigga::AdminApiClient::Proxies::Admin
5
+ end
6
+
7
+ describe Trigga::AdminApiClient::Proxies::Admin do
8
+ describe "get_stats" do
9
+ before do
10
+ @opts = {:abc => 123}
11
+ end
12
+
13
+ it "should call make_call" do
14
+ Trigga::AdminApiClient.should_receive(:make_call).with("admin","stats",@opts)
15
+ AdminApiClientProxyTest.new.get_stats @opts
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,101 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..', 'spec_helper'))
2
+
3
+ class ApiApiClientProxyTest
4
+ include Trigga::AdminApiClient::Proxies::Api
5
+ end
6
+
7
+ describe Trigga::AdminApiClient::Proxies::Api do
8
+ before do
9
+ ApiApiClientProxyTest.stub!(:require_one_of).and_return(true)
10
+ ApiApiClientProxyTest.stub!(:require_param).and_return(true)
11
+ Trigga::AdminApiClient.stub!(:make_call).and_return(true)
12
+ @opts = {:abc => 123, :api_key => "blah"}
13
+ end
14
+
15
+ describe "common_params" do
16
+ ApiApiClientProxyTest.new.send("common_params").should == [:page, :per_page, :max_tags, :site_key, :api_key]
17
+ end
18
+
19
+ describe "make_api_call" do
20
+ before do
21
+
22
+ end
23
+
24
+ it "should require a site or site_id" do
25
+ ApiApiClientProxyTest.should_receive(:require_one_of).with(@opts, :site_key, :site_id)
26
+ ApiApiClientProxyTest.new.send("make_api_call","endpoint",@opts)
27
+ end
28
+
29
+ it "should call make_call filtering out bad params" do
30
+ Trigga::AdminApiClient.should_receive(:make_call).with("api","endpoint",{:api_key => "blah"})
31
+ ApiApiClientProxyTest.new.send("make_api_call","endpoint",@opts)
32
+ end
33
+ end
34
+
35
+
36
+ describe "get_channels" do
37
+ it "should call make_api_call" do
38
+ ApiApiClientProxyTest.should_receive(:make_api_call).with("channels",@opts)
39
+ ApiApiClientProxyTest.get_channels @opts
40
+ end
41
+ end
42
+
43
+
44
+ describe "get_channel_items" do
45
+ before do
46
+ @opts = @opts.merge(:channel_id => 42)
47
+ end
48
+
49
+ it "should require the channel_id" do
50
+ ApiApiClientProxyTest.should_receive(:require_param).with(@opts, :channel_id)
51
+ ApiApiClientProxyTest.get_channel_items @opts
52
+ end
53
+
54
+ it "should call make_api_call" do
55
+ ApiApiClientProxyTest.should_receive(:make_api_call).with("channels/42",@opts)
56
+ ApiApiClientProxyTest.get_channel_items @opts
57
+ end
58
+ end
59
+
60
+
61
+ describe "get_sources" do
62
+ it "should call make_api_call" do
63
+ ApiApiClientProxyTest.should_receive(:make_api_call).with("sources",@opts)
64
+ ApiApiClientProxyTest.get_sources @opts
65
+ end
66
+ end
67
+
68
+
69
+ describe "get_item_tags" do
70
+ it "should call make_api_call" do
71
+ ApiApiClientProxyTest.should_receive(:make_api_call).with("item_tags",@opts)
72
+ ApiApiClientProxyTest.get_item_tags @opts
73
+ end
74
+ end
75
+
76
+
77
+ describe "get_latest_items" do
78
+ it "should call make_api_call" do
79
+ ApiApiClientProxyTest.should_receive(:make_api_call).with("items",@opts)
80
+ ApiApiClientProxyTest.get_latest_items @opts
81
+ end
82
+ end
83
+
84
+
85
+ describe "get_item_details" do
86
+ before do
87
+ @opts = @opts.merge(:item_id => 42)
88
+ end
89
+
90
+ it "should require the channel_id" do
91
+ ApiApiClientProxyTest.should_receive(:require_param).with(@opts, :item_id)
92
+ ApiApiClientProxyTest.get_item_details @opts
93
+ end
94
+
95
+ it "should call make_api_call" do
96
+ ApiApiClientProxyTest.should_receive(:make_api_call).with("items/42",@opts)
97
+ ApiApiClientProxyTest.get_item_details @opts
98
+ end
99
+ end
100
+ end
101
+
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
5
+ --backtrace
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'trigga/admin_api_client'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
metadata ADDED
@@ -0,0 +1,303 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itrigga-admin_api_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Anson Kelly
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-11 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: itrigga-core_ext
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ requirement: *id001
34
+ type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: itrigga-param_fu
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ requirement: *id002
48
+ type: :runtime
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ name: itrigga-net_helper
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirement: *id003
62
+ type: :runtime
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ name: hashie
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirement: *id004
76
+ type: :runtime
77
+ - !ruby/object:Gem::Dependency
78
+ prerelease: false
79
+ name: rspec
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - "="
84
+ - !ruby/object:Gem::Version
85
+ hash: 27
86
+ segments:
87
+ - 1
88
+ - 3
89
+ - 0
90
+ version: 1.3.0
91
+ requirement: *id005
92
+ type: :development
93
+ - !ruby/object:Gem::Dependency
94
+ prerelease: false
95
+ name: rspec-rails
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - "="
100
+ - !ruby/object:Gem::Version
101
+ hash: 31
102
+ segments:
103
+ - 1
104
+ - 3
105
+ - 2
106
+ version: 1.3.2
107
+ requirement: *id006
108
+ type: :development
109
+ - !ruby/object:Gem::Dependency
110
+ prerelease: false
111
+ name: bundler
112
+ version_requirements: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ hash: 23
118
+ segments:
119
+ - 1
120
+ - 0
121
+ - 0
122
+ version: 1.0.0
123
+ requirement: *id007
124
+ type: :development
125
+ - !ruby/object:Gem::Dependency
126
+ prerelease: false
127
+ name: jeweler
128
+ version_requirements: &id008 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ hash: 7
134
+ segments:
135
+ - 1
136
+ - 6
137
+ - 4
138
+ version: 1.6.4
139
+ requirement: *id008
140
+ type: :development
141
+ - !ruby/object:Gem::Dependency
142
+ prerelease: false
143
+ name: rcov
144
+ version_requirements: &id009 !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ requirement: *id009
154
+ type: :development
155
+ - !ruby/object:Gem::Dependency
156
+ prerelease: false
157
+ name: fastercsv
158
+ version_requirements: &id010 !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ requirement: *id010
168
+ type: :development
169
+ - !ruby/object:Gem::Dependency
170
+ prerelease: false
171
+ name: hpricot
172
+ version_requirements: &id011 !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ hash: 3
178
+ segments:
179
+ - 0
180
+ version: "0"
181
+ requirement: *id011
182
+ type: :development
183
+ - !ruby/object:Gem::Dependency
184
+ prerelease: false
185
+ name: json_pure
186
+ version_requirements: &id012 !ruby/object:Gem::Requirement
187
+ none: false
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ hash: 3
192
+ segments:
193
+ - 0
194
+ version: "0"
195
+ requirement: *id012
196
+ type: :development
197
+ - !ruby/object:Gem::Dependency
198
+ prerelease: false
199
+ name: itrigga-core_ext
200
+ version_requirements: &id013 !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ hash: 3
206
+ segments:
207
+ - 0
208
+ version: "0"
209
+ requirement: *id013
210
+ type: :runtime
211
+ - !ruby/object:Gem::Dependency
212
+ prerelease: false
213
+ name: itrigga-param_fu
214
+ version_requirements: &id014 !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ hash: 3
220
+ segments:
221
+ - 0
222
+ version: "0"
223
+ requirement: *id014
224
+ type: :runtime
225
+ - !ruby/object:Gem::Dependency
226
+ prerelease: false
227
+ name: itrigga-net_helper
228
+ version_requirements: &id015 !ruby/object:Gem::Requirement
229
+ none: false
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ hash: 3
234
+ segments:
235
+ - 0
236
+ version: "0"
237
+ requirement: *id015
238
+ type: :runtime
239
+ description: Wraps API calls to iTrigga applications
240
+ email: support@itrigga.com
241
+ executables: []
242
+
243
+ extensions: []
244
+
245
+ extra_rdoc_files:
246
+ - LICENSE.txt
247
+ - README.rdoc
248
+ files:
249
+ - .document
250
+ - .rspec
251
+ - Gemfile
252
+ - Gemfile.lock
253
+ - LICENSE.txt
254
+ - README.rdoc
255
+ - Rakefile
256
+ - VERSION
257
+ - configuration.yml
258
+ - lib/trigga/admin_api_client.rb
259
+ - lib/trigga/admin_api_client/admin_api_client.rb
260
+ - lib/trigga/admin_api_client/proxies/admin.rb
261
+ - lib/trigga/admin_api_client/proxies/api.rb
262
+ - lib/trigga/admin_api_client/proxies/search_tracker.rb
263
+ - spec/admin_api_client_spec.rb
264
+ - spec/proxies/admin_spec.rb
265
+ - spec/proxies/api_spec.rb
266
+ - spec/spec.opts
267
+ - spec/spec_helper.rb
268
+ has_rdoc: true
269
+ homepage: http://rubygems.org/itrigga-admin_api_client
270
+ licenses:
271
+ - MIT
272
+ post_install_message:
273
+ rdoc_options: []
274
+
275
+ require_paths:
276
+ - lib
277
+ required_ruby_version: !ruby/object:Gem::Requirement
278
+ none: false
279
+ requirements:
280
+ - - ">="
281
+ - !ruby/object:Gem::Version
282
+ hash: 3
283
+ segments:
284
+ - 0
285
+ version: "0"
286
+ required_rubygems_version: !ruby/object:Gem::Requirement
287
+ none: false
288
+ requirements:
289
+ - - ">="
290
+ - !ruby/object:Gem::Version
291
+ hash: 3
292
+ segments:
293
+ - 0
294
+ version: "0"
295
+ requirements: []
296
+
297
+ rubyforge_project:
298
+ rubygems_version: 1.3.7
299
+ signing_key:
300
+ specification_version: 3
301
+ summary: Wraps API calls to iTrigga applications
302
+ test_files: []
303
+