active_forms 0.3.1 → 0.3.2

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/active_forms.gemspec CHANGED
@@ -1,4 +1,5 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: UTF-8
2
+
2
3
  require File.expand_path('../lib/active_forms/version', __FILE__)
3
4
 
4
5
  Gem::Specification.new do |gem|
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActiveForms
4
4
  class Configuration
5
- attr_accessor :api_url, :url, :base_url, :api_key, :secret_key, :logger
5
+ attr_accessor :api_url, :url, :base_url, :api_key, :secret_key, :logger, :basic_auth
6
6
 
7
7
  def initialize
8
8
  @api_url = { :protocol => "https", :host => 'api.activeforms.com' }
@@ -6,7 +6,7 @@ require 'httparty'
6
6
 
7
7
  module ActiveForms
8
8
  class Request
9
- attr_reader :http_method, :path, :params, :api_params, :uri
9
+ attr_reader :http_method, :path, :params, :api_params, :uri, :options
10
10
 
11
11
  class << self
12
12
  def get(path, all_params = {})
@@ -44,15 +44,16 @@ module ActiveForms
44
44
  @api_params["apiSig"] = api_sig
45
45
 
46
46
  @uri = build_uri
47
+ @options = build_options
47
48
  end
48
49
 
49
50
  def perform
50
51
  ActiveForms.log("[ActiveForms] Request: #{http_method.upcase} #{uri}")
51
52
  begin
52
- response = HTTParty.send(http_method.downcase, uri)
53
+ response = HTTParty.send(http_method.downcase, uri, options)
53
54
  verify_response(response)
54
55
  rescue
55
- response = HTTParty.send(http_method.downcase, uri)
56
+ response = HTTParty.send(http_method.downcase, uri, options)
56
57
  verify_response(response)
57
58
  end
58
59
  response
@@ -73,6 +74,10 @@ module ActiveForms
73
74
  url_with_path + "?" + [params, api_params].flatten.join("&")
74
75
  end
75
76
 
77
+ def build_options
78
+ ActiveForms.configuration.basic_auth ? { :basic_auth => ActiveForms.configuration.basic_auth } : {}
79
+ end
80
+
76
81
  def url_with_path
77
82
  url = ActiveForms.configuration.api_url[:protocol] + "://" + ActiveForms.configuration.api_url[:host]
78
83
  [url, ActiveForms.configuration.base_url, path].join('/')
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  module ActiveForms
2
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
3
5
  end
@@ -58,6 +58,11 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
58
58
  end
59
59
  end
60
60
  end
61
+
62
+ should "have empty options" do
63
+ expected = {}
64
+ assert_equal expected, @request.options
65
+ end
61
66
  end
62
67
 
63
68
  context "POST request" do
@@ -138,4 +143,21 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
138
143
  end
139
144
  end
140
145
  end
146
+
147
+ context "configured with basic_auth" do
148
+ setup do
149
+ configure(:basic_auth => { :username => "user", :password => "pass" })
150
+ end
151
+
152
+ context "request" do
153
+ setup do
154
+ @request = ActiveForms::Request.new(:get, "entries")
155
+ end
156
+
157
+ should "have correct options" do
158
+ expected = { :basic_auth => { :username => "user", :password => "pass" } }
159
+ assert_equal expected, @request.options
160
+ end
161
+ end
162
+ end
141
163
  end
data/test/test_helper.rb CHANGED
@@ -15,13 +15,16 @@ class Test::Unit::TestCase
15
15
  FakeWeb.clean_registry
16
16
  end
17
17
 
18
- def configure
18
+ def configure(opts = {})
19
19
  ActiveForms.configure do |c|
20
20
  c.api_url = { :protocol => "https", :host => "api.example.com" }
21
21
  c.url = { :protocol => "https", :host => "www.example.com" }
22
22
  c.base_url = "client"
23
23
  c.api_key = "123456"
24
24
  c.secret_key = "abcdef"
25
+ opts.each do |k, v|
26
+ c.send("#{k}=", v)
27
+ end
25
28
  end
26
29
  end
27
30
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_forms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Micha\xC5\x82 Szajbe"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-27 00:00:00 Z
18
+ date: 2012-06-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activesupport