woopy 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in woopy.gemspec
4
+ gemspec
data/README ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/lib/woopy.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'active_resource'
5
+
6
+ require 'woopy/version'
7
+ require 'woopy/client'
8
+ require 'woopy/resource'
9
+ require 'woopy/user'
10
+ require 'woopy/account'
11
+ require 'woopy/employment'
12
+ require 'woopy/ownership'
13
+
14
+ def Woopy(options = {})
15
+ Woopy::Client.new(options)
16
+ end
@@ -0,0 +1,13 @@
1
+ module Woopy
2
+ class Account < Resource
3
+
4
+ def employ(user)
5
+ Employment.create(account_id: self.id, user_id: user.id)
6
+ end
7
+
8
+ def make_owner(user)
9
+ Ownership.create(account_id: self.id, user_id: user.id)
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Woopy
2
+ class Client
3
+ def initialize(options)
4
+ @token = options[:token]
5
+ Resource.headers['X-WoopleToken'] = @token
6
+ end
7
+
8
+ def verify
9
+ Resource.connection.get(Resource.prefix + 'verify', Resource.headers).code == 200
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Woopy
2
+ class Employment < Resource
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Woopy
2
+ class Ownership < Resource
3
+
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ module Woopy
2
+ SITE_BASE = 'https://api.woople.com/services/v1/'
3
+
4
+ class Resource < ActiveResource::Base
5
+ Resource.site = SITE_BASE
6
+
7
+ class << self
8
+ # If headers are not defined in a given subclass, then obtain headers from the superclass.
9
+ # Taken from the Harvest gem: github.com/aiaio/harvest
10
+ def headers
11
+ if defined?(@headers)
12
+ @headers
13
+ elsif superclass != Object && superclass.headers
14
+ superclass.headers
15
+ else
16
+ @headers ||= {}
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/woopy/user.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Woopy
2
+ class User < Resource
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Woopy
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ require 'woopy'
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+ end
14
+
15
+ def request_headers(token)
16
+ {"Content-Type" => "application/json", "X-WoopleToken" => token }
17
+ end
18
+
19
+ def account_response
20
+ { account: account_attributes.merge(id: 1) }.to_json
21
+ end
22
+
23
+ def account_attributes
24
+ { name: "Account", subdomain: "subdomain1" }
25
+ end
26
+
27
+ def user_response
28
+ { user: user_attributes.merge(id: 1) }.to_json
29
+ end
30
+
31
+ def user_attributes
32
+ { name: "User Name", email: "user@example.com" }
33
+ end
34
+
35
+ def employment_response
36
+ { employment: employment_attributes.merge(id: 1) }.to_json
37
+ end
38
+
39
+ def employment_attributes
40
+ { account_id: 1, user_id: 1 }
41
+ end
42
+
43
+ def ownership_response
44
+ { ownership: ownership_attributes.merge(id: 1) }.to_json
45
+ end
46
+
47
+ def ownership_attributes
48
+ { account_id: 1, user_id: 1 }
49
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Woopy::Account do
4
+
5
+ before do
6
+ @token = 'foo'
7
+ Woopy(token: @token)
8
+ ActiveResource::HttpMock.respond_to do |mock|
9
+ mock.post( '/services/v1/accounts.json', request_headers(@token), account_response )
10
+ mock.post( '/services/v1/users.json', request_headers(@token), user_response )
11
+ mock.post( '/services/v1/employments.json', request_headers(@token), employment_response )
12
+ mock.post( '/services/v1/ownerships.json', request_headers(@token), ownership_response )
13
+ end
14
+ end
15
+
16
+ describe "#save" do
17
+
18
+ context "valid name and subdomain" do
19
+ before do
20
+ @account = Woopy::Account.new(account_attributes)
21
+ end
22
+ it 'saves correctly' do
23
+ @account.save.should be_true
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ context "with an existing user" do
30
+
31
+ before do
32
+ @account = Woopy::Account.create(account_attributes)
33
+ @user = Woopy::User.create(user_attributes)
34
+ end
35
+
36
+ describe "#employ" do
37
+ subject { @account.employ(@user) }
38
+
39
+ it { should be_kind_of Woopy::Employment }
40
+ it { should be_persisted }
41
+ end
42
+
43
+ describe "#make_owner" do
44
+ subject { @account.make_owner(@user) }
45
+
46
+ it { should be_kind_of Woopy::Ownership }
47
+ it { should be_persisted }
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe Woopy::Client do
4
+ before { @token = 'foo' }
5
+
6
+ describe '#new' do
7
+ it "sets the header token" do
8
+ Woopy(token: @token)
9
+ Woopy::Resource.headers['X-WoopleToken'].should eq(@token)
10
+ end
11
+ end
12
+
13
+ describe '#verify' do
14
+
15
+ context 'given valid token' do
16
+ before { mock_verify(200) }
17
+
18
+ subject { Woopy(token: @token).verify }
19
+
20
+ it { should be_true }
21
+ end
22
+
23
+ context 'given invalid token' do
24
+ before { mock_verify(401) }
25
+
26
+ subject { Woopy(token: @token).verify }
27
+
28
+ it { expect { subject }.to raise_error }
29
+ end
30
+ end
31
+
32
+ def mock_verify(status_code)
33
+ ActiveResource::HttpMock.respond_to do |mock|
34
+ mock.get '/services/v1/verify', {"Accept" => "application/json", "X-WoopleToken" => @token }, '', status_code
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Woopy::User do
4
+
5
+ before do
6
+ @token = 'foo'
7
+ Woopy(token: @token)
8
+ end
9
+
10
+ describe "#save" do
11
+
12
+ before do
13
+ ActiveResource::HttpMock.respond_to do |mock|
14
+ mock.post( '/services/v1/users.json', request_headers(@token), user_response)
15
+ end
16
+ end
17
+
18
+ context "valid name and email" do
19
+ before do
20
+ @user = Woopy::User.new(user_attributes)
21
+ end
22
+ it 'saves correctly' do
23
+ @user.save.should be_true
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
data/woopy.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "woopy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "woopy"
7
+ s.version = Woopy::VERSION
8
+ s.authors = ["Big Bang Technology"]
9
+ s.email = ["developers@bigbangtechnology.com"]
10
+ s.homepage = "http://woople.com/"
11
+ s.summary = %q{Woople API Wrapper}
12
+ s.description = %q{Wraps the Woople API as ActiveResources}
13
+
14
+ s.rubyforge_project = "woopy"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec", "~> 2.8"
23
+ s.add_development_dependency "json"
24
+ # s.add_runtime_dependency "rest-client"
25
+ s.add_dependency 'activeresource', '~> 3.1'
26
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: woopy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Big Bang Technology
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70282874275880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.8'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70282874275880
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70282874275280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70282874275280
36
+ - !ruby/object:Gem::Dependency
37
+ name: activeresource
38
+ requirement: &70282874289360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '3.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70282874289360
47
+ description: Wraps the Woople API as ActiveResources
48
+ email:
49
+ - developers@bigbangtechnology.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rspec
56
+ - Gemfile
57
+ - README
58
+ - Rakefile
59
+ - lib/woopy.rb
60
+ - lib/woopy/account.rb
61
+ - lib/woopy/client.rb
62
+ - lib/woopy/employment.rb
63
+ - lib/woopy/ownership.rb
64
+ - lib/woopy/resource.rb
65
+ - lib/woopy/user.rb
66
+ - lib/woopy/version.rb
67
+ - spec/spec_helper.rb
68
+ - spec/woopy/account_spec.rb
69
+ - spec/woopy/client_spec.rb
70
+ - spec/woopy/user_spec.rb
71
+ - woopy.gemspec
72
+ homepage: http://woople.com/
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project: woopy
92
+ rubygems_version: 1.8.10
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Woople API Wrapper
96
+ test_files:
97
+ - spec/spec_helper.rb
98
+ - spec/woopy/account_spec.rb
99
+ - spec/woopy/client_spec.rb
100
+ - spec/woopy/user_spec.rb
101
+ has_rdoc: