Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add ability to configure using a JSON string

  • Loading branch information...
commit e103a3fafdd9ed25c69492504c69238c89dacd58 1 parent 720077f
Jacques Crocker authored November 05, 2010
22  lib/recurly.rb
... ...
@@ -1,5 +1,6 @@
1 1
 require 'active_resource'
2 2
 require 'active_support/deprecation'
  3
+require 'active_support/json'
3 4
 require 'cgi'
4 5
 
5 6
 require 'recurly/version'
@@ -53,6 +54,8 @@ def configure
53 54
       true
54 55
     end
55 56
 
  57
+    # allows configuration from a yml file that contains the fields:
  58
+    # username,password,site
56 59
     def configure_from_yaml(path = nil)
57 60
       configure do |c|
58 61
         # parse configuration from yml
@@ -66,19 +69,14 @@ def configure_from_yaml(path = nil)
66 69
       end
67 70
     end
68 71
 
69  
-    def configure_from_heroku(config_string)
  72
+    # allows configuration from a json string that contains the fields:
  73
+    # username,password,site
  74
+    def configure_from_json(json_string)
  75
+      config_data = ActiveSupport::JSON.decode(json_string)
70 76
       configure do |c|
71  
-
72  
-        # pull out the site
73  
-        parts = config_string.split("@")
74  
-        c.site = parts.last
75  
-        config_string = parts[0..-2].join("@")
76  
-
77  
-        # pull out the username and password
78  
-        parts = config_string.split(":")
79  
-        c.username = parts.first
80  
-        c.password = parts[1..-1].join(":")
81  
-
  77
+        c.username = config_data['username']
  78
+        c.password = config_data['password']
  79
+        c.site = config_data['site']
82 80
       end
83 81
     end
84 82
   end
2  lib/recurly/rails3/railtie.rb
@@ -7,7 +7,7 @@ class Railtie < ::Rails::Railtie
7 7
     config.after_initialize do
8 8
       unless Recurly.configured?
9 9
         if ENV["RECURLY_CONFIG"]
10  
-          ::Recurly.configure_from_heroku(ENV["RECURLY_CONFIG"])
  10
+          ::Recurly.configure_from_json(ENV["RECURLY_CONFIG"])
11 11
         else
12 12
           # setup recurly authentication details for testing
13 13
           ::Recurly.configure_from_yaml
23  spec/unit/config_spec.rb
@@ -11,16 +11,25 @@
11 11
     end
12 12
   end
13 13
 
14  
-  context "loading from heroku config string" do
15  
-    it "should load configuration from a config string" do
16  
-      Recurly.configure_from_heroku("someuser:somepass@https://recurlytest3-test.recurly.com")
17  
-      Recurly.username.should == "someuser"
  14
+  context "loading from json" do
  15
+    it "should load configuration from a json config string" do
  16
+      Recurly.configure_from_json({
  17
+        :username => "someuser@heroku.com",
  18
+        :password => "somepass",
  19
+        :site => "https://recurlytest3-test.recurly.com"
  20
+      }.to_json)
  21
+      Recurly.username.should == "someuser@heroku.com"
18 22
       Recurly.password.should == "somepass"
19 23
       Recurly.site.should == "https://recurlytest3-test.recurly.com"
20 24
 
21  
-      # test with some crazy chars
22  
-      Recurly.configure_from_heroku("someuser:*$&!!::@&!)*)*_@https://recurlytest3-test.recurly.com")
23  
-      Recurly.username.should == "someuser"
  25
+      # test with some crazy chars in the password
  26
+      Recurly.configure_from_json({
  27
+        :username => "api-someuser@heroku.com",
  28
+        :password => "*$&!!::@&!)*)*_",
  29
+        :site => "https://recurlytest3-test.recurly.com"
  30
+      }.to_json)
  31
+
  32
+      Recurly.username.should == "api-someuser@heroku.com"
24 33
       Recurly.password.should == "*$&!!::@&!)*)*_"
25 34
       Recurly.site.should == "https://recurlytest3-test.recurly.com"
26 35
     end

0 notes on commit e103a3f

Please sign in to comment.
Something went wrong with that request. Please try again.