woopy 0.1.1 → 0.1.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.
@@ -3,10 +3,29 @@ module Woopy
3
3
  def initialize(options)
4
4
  @token = options[:token]
5
5
  Resource.headers['X-WoopleToken'] = @token
6
+
7
+ configure_end_point
6
8
  end
7
-
9
+
8
10
  def verify
9
11
  Resource.connection.get(Resource.prefix + 'verify', Resource.headers).code == 200
10
12
  end
13
+
14
+ private
15
+
16
+ def configure_end_point
17
+ case current_environment
18
+ when "production"
19
+ Resource.site = "https://api.woople.com/services/v1/"
20
+ when "staging"
21
+ Resource.site = "https://api.testwoople.com/services/v1/"
22
+ else
23
+ Resource.site = "https://api.woople.local:8080/services/v1/"
24
+ end
25
+ end
26
+
27
+ def current_environment
28
+ ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
29
+ end
11
30
  end
12
31
  end
@@ -1,9 +1,5 @@
1
1
  module Woopy
2
- SITE_BASE = 'https://api.woople.com/services/v1/'
3
-
4
2
  class Resource < ActiveResource::Base
5
- Resource.site = SITE_BASE
6
-
7
3
  class << self
8
4
  # If headers are not defined in a given subclass, then obtain headers from the superclass.
9
5
  # Taken from the Harvest gem: github.com/aiaio/harvest
@@ -1,3 +1,3 @@
1
1
  module Woopy
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -8,27 +8,71 @@ describe Woopy::Client do
8
8
  Woopy(token: @token)
9
9
  Woopy::Resource.headers['X-WoopleToken'].should eq(@token)
10
10
  end
11
+
12
+ context "production environment" do
13
+ before do
14
+ ENV["RAILS_ENV"] = "production"
15
+ Woopy(token: @token)
16
+ end
17
+
18
+ it "sets the end point" do
19
+ Woopy::Resource.site.to_s.should eq("https://api.woople.com/services/v1/")
20
+ end
21
+ end
22
+
23
+ context "staging environment" do
24
+ before do
25
+ ENV["RAILS_ENV"] = "staging"
26
+ Woopy(token: @token)
27
+ end
28
+
29
+ it "sets the end point" do
30
+ Woopy::Resource.site.to_s.should eq("https://api.testwoople.com/services/v1/")
31
+ end
32
+ end
33
+
34
+ context "local development environment" do
35
+ before do
36
+ ENV["RAILS_ENV"] = "development"
37
+ Woopy(token: @token)
38
+ end
39
+
40
+ it "sets the end point" do
41
+ Woopy::Resource.site.to_s.should eq("https://api.woople.local:8080/services/v1/")
42
+ end
43
+ end
44
+
45
+ context "undefined environment" do
46
+ before do
47
+ ENV["RAILS_ENV"] = nil
48
+ Woopy(token: @token)
49
+ end
50
+
51
+ it "sets the default end point" do
52
+ Woopy::Resource.site.to_s.should eq("https://api.woople.local:8080/services/v1/")
53
+ end
54
+ end
11
55
  end
12
56
 
13
57
  describe '#verify' do
14
-
58
+
15
59
  context 'given valid token' do
16
60
  before { mock_verify(200) }
17
-
61
+
18
62
  subject { Woopy(token: @token).verify }
19
-
63
+
20
64
  it { should be_true }
21
65
  end
22
-
66
+
23
67
  context 'given invalid token' do
24
68
  before { mock_verify(401) }
25
-
69
+
26
70
  subject { Woopy(token: @token).verify }
27
-
71
+
28
72
  it { expect { subject }.to raise_error }
29
73
  end
30
74
  end
31
-
75
+
32
76
  def mock_verify(status_code)
33
77
  ActiveResource::HttpMock.respond_to do |mock|
34
78
  mock.get '/services/v1/verify', {"Accept" => "application/json", "X-WoopleToken" => @token }, '', status_code
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "rspec", "~> 2.8"
23
23
  s.add_development_dependency "json"
24
+ s.add_development_dependency "gem-release"
24
25
  # s.add_runtime_dependency "rest-client"
25
26
  s.add_dependency 'activeresource', '~> 3.1'
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: woopy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-12 00:00:00.000000000 Z
12
+ date: 2012-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70282874275880 !ruby/object:Gem::Requirement
16
+ requirement: &70217104009120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.8'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70282874275880
24
+ version_requirements: *70217104009120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70282874275280 !ruby/object:Gem::Requirement
27
+ requirement: &70217104007520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70282874275280
35
+ version_requirements: *70217104007520
36
+ - !ruby/object:Gem::Dependency
37
+ name: gem-release
38
+ requirement: &70217104006340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70217104006340
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: activeresource
38
- requirement: &70282874289360 !ruby/object:Gem::Requirement
49
+ requirement: &70217104005740 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,7 +54,7 @@ dependencies:
43
54
  version: '3.1'
44
55
  type: :runtime
45
56
  prerelease: false
46
- version_requirements: *70282874289360
57
+ version_requirements: *70217104005740
47
58
  description: Wraps the Woople API as ActiveResources
48
59
  email:
49
60
  - developers@bigbangtechnology.com
@@ -98,4 +109,3 @@ test_files:
98
109
  - spec/woopy/account_spec.rb
99
110
  - spec/woopy/client_spec.rb
100
111
  - spec/woopy/user_spec.rb
101
- has_rdoc: