animoto 0.0.0.alpha2 → 0.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ module Animoto
36
36
  :post => Net::HTTP::Post
37
37
  }
38
38
 
39
- attr_accessor :key, :secret
39
+ attr_accessor :key, :secret, :endpoint
40
40
  attr_reader :format
41
41
 
42
42
  # Creates a new Client object which handles credentials, versioning, making requests, and
@@ -44,7 +44,8 @@ module Animoto
44
44
  #
45
45
  # If you have your key and secret in ~/.animotorc or /etc/.animotorc, those credentials will
46
46
  # be read from those files (in that order) whenever you make a new Client if you don't specify
47
- # them explicitly.
47
+ # them explicitly. You can also specify the endpoint (staging, sandbox, etc.) in the rc file.
48
+ # The default endpoint will be used if one isn't specified.
48
49
  #
49
50
  # @param [String] key the API key for your account
50
51
  # @param [String] secret the secret key for your account
@@ -55,20 +56,22 @@ module Animoto
55
56
  options = args.last.is_a?(Hash) ? args.pop : {}
56
57
  @key = args[0]
57
58
  @secret = args[1]
59
+ @endpoint = options[:endpoint]
60
+
61
+ home_path = File.expand_path '~/.animotorc'
62
+ config = if File.exist?(home_path)
63
+ YAML.load(File.read(home_path))
64
+ elsif File.exist?('/etc/.animotorc')
65
+ YAML.load(File.read('/etc/.animotorc'))
66
+ end
67
+ @key ||= config['key']
68
+ @secret ||= config['secret']
69
+ @endpoint ||= config['endpoint']
58
70
  unless @key && @secret
59
- home_path = File.expand_path '~/.animotorc'
60
- config = if File.exist?(home_path)
61
- YAML.load(File.read(home_path))
62
- elsif File.exist?('/etc/.animotorc')
63
- YAML.load(File.read('/etc/.animotorc'))
64
- end
65
- if config
66
- @key ||= config['key']
67
- @secret ||= config['secret']
68
- else
69
- raise ArgumentError, "You must supply your key and secret"
70
- end
71
+ raise ArgumentError, "You must supply your key and secret"
71
72
  end
73
+
74
+ @endpoint ||= API_ENDPOINT
72
75
  @format = 'json'
73
76
  end
74
77
 
@@ -140,7 +143,7 @@ module Animoto
140
143
  # @return [Hash] deserialized JSON response body
141
144
  def send_manifest manifest, endpoint, options = {}
142
145
  # request(:post, endpoint, manifest.to_json, { "Accept" => "application/#{format}", "Content-Type" => content_type_of(manifest) }, options)
143
- u = URI.parse(API_ENDPOINT)
146
+ u = URI.parse(endpoint)
144
147
  u.path = endpoint
145
148
  request(:post, u, manifest.to_json, { "Accept" => "application/#{format}", "Content-Type" => content_type_of(manifest) }, options)
146
149
  end
data/lib/animoto.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Animoto
2
2
  def self.version
3
- "0.0.0.alpha2"
3
+ "0.0.0.alpha3"
4
4
  end
5
5
  end
@@ -9,7 +9,7 @@ describe Animoto::Client do
9
9
  @object ||= Object.new
10
10
  end
11
11
 
12
- describe "supplying credentials" do
12
+ describe "supplying credentials and endpoint" do
13
13
  describe "manually" do
14
14
  it "should accept the key and secret as the first two parameters on initialization" do
15
15
  c = Animoto::Client.new "key", "secret"
@@ -17,6 +17,11 @@ describe Animoto::Client do
17
17
  c.secret.should == "secret"
18
18
  end
19
19
 
20
+ it "should accept an endpoint as an option" do
21
+ c = Animoto::Client.new "key", "secret", :endpoint => "https://api.animoto.com/"
22
+ c.endpoint.should == "https://api.animoto.com/"
23
+ end
24
+
20
25
  describe "when the secret isn't specified (i.e. only 1 parameter was passed)" do
21
26
  before do
22
27
  File.stubs(:exist?).returns(false) # <= to keep it from finding our .animotorc files
@@ -26,13 +31,20 @@ describe Animoto::Client do
26
31
  lambda { Animoto::Client.new "key" }.should raise_error
27
32
  end
28
33
  end
34
+
35
+ describe "when the endpoint isn't specified" do
36
+ it "should set the endpoint to the default" do
37
+ c = Animoto::Client.new "key", "secret"
38
+ c.endpoint.should == Animoto::Client::API_ENDPOINT
39
+ end
40
+ end
29
41
  end
30
42
 
31
43
  describe "automatically" do
32
44
  before do
33
45
  @home_path = File.expand_path("~/.animotorc")
34
46
  @etc_path = "/etc/.animotorc"
35
- @config = "key: joe\nsecret: secret"
47
+ @config = "key: joe\nsecret: secret\nendpoint: https://api.animoto.com/"
36
48
  end
37
49
 
38
50
  describe "when ~/.animotorc exists" do
@@ -45,6 +57,7 @@ describe Animoto::Client do
45
57
  c = Animoto::Client.new
46
58
  c.key.should == "joe"
47
59
  c.secret.should == "secret"
60
+ c.endpoint.should == "https://api.animoto.com/"
48
61
  end
49
62
  end
50
63
 
@@ -63,6 +76,7 @@ describe Animoto::Client do
63
76
  c = Animoto::Client.new
64
77
  c.key.should == "joe"
65
78
  c.secret.should == "secret"
79
+ c.endpoint.should == "https://api.animoto.com/"
66
80
  end
67
81
  end
68
82
 
@@ -74,7 +88,7 @@ describe Animoto::Client do
74
88
  end
75
89
  end
76
90
  end
77
-
91
+
78
92
  describe "finding an instance by identifier" do
79
93
  before do
80
94
  @url = "https://api.animoto.com/storyboards/1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: animoto
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1710980560
4
+ hash: -1710980559
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
9
  - 0
10
- - alpha2
11
- version: 0.0.0.alpha2
10
+ - alpha3
11
+ version: 0.0.0.alpha3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Animoto
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-30 00:00:00 -04:00
19
+ date: 2010-09-07 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency