freelancer-rails 0.1.0
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/Gemfile +3 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +20 -0
- data/README.rdoc +52 -0
- data/Rakefile +79 -0
- data/VERSION +1 -0
- data/app/controllers/freelancer/rails/authorizations_controller.rb +32 -0
- data/app/views/freelancer/rails/authorizations/new.html.erb +13 -0
- data/lib/freelancer-rails.rb +6 -0
- data/lib/freelancer-rails/configuration.rb +53 -0
- data/lib/freelancer-rails/controllers/helpers.rb +34 -0
- data/lib/freelancer-rails/routes.rb +17 -0
- data/rails/init.rb +1 -0
- data/test/helper.rb +10 -0
- data/test/test_freelancer-rails.rb +7 -0
- metadata +100 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
freelancer (0.1.1)
|
5
|
+
htmlentities (>= 4.2.1)
|
6
|
+
json_mapper (>= 0.2.1)
|
7
|
+
oauth (>= 0.4.0)
|
8
|
+
htmlentities (4.2.1)
|
9
|
+
json (1.4.6)
|
10
|
+
json_mapper (0.2.1)
|
11
|
+
json (>= 1.4.3)
|
12
|
+
oauth (0.4.2)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
freelancer (= 0.1.1)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Trond Arve Nordheim
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= Freelancer Rails API
|
2
|
+
|
3
|
+
Copyright (C) 2010 Trond Arve Nordheim - {Binary Marbles}[http://www.binarymarbles.com/]
|
4
|
+
|
5
|
+
== NOTICE
|
6
|
+
|
7
|
+
This is a project under heavy development. The API is far from stable yet, and
|
8
|
+
the code is very unclean in some places. The API won't be considered stable
|
9
|
+
until all the full Freelancer.com APIs is implemented and have tests verifying
|
10
|
+
that they work like they should.
|
11
|
+
|
12
|
+
== Description
|
13
|
+
|
14
|
+
A Ruby gem for integrating the Freelancer.com API services into a Ruby on Rails application.
|
15
|
+
|
16
|
+
== Features
|
17
|
+
|
18
|
+
* oAuth authorization
|
19
|
+
* Per-environment configuration and sandboxing support, and support from setting API configuration from environment variables.
|
20
|
+
|
21
|
+
== Issues and missing features
|
22
|
+
|
23
|
+
* No tests yet.
|
24
|
+
* No elegant way of hooking into post-authorization-events to retrieve the access token and access secret for storing on the current users profile.
|
25
|
+
* No generators available.
|
26
|
+
* Lacks documentation.
|
27
|
+
|
28
|
+
== Documentation
|
29
|
+
|
30
|
+
* RDoc: http://rdoc.info/projects/tanordheim/freelancer-rails
|
31
|
+
* Usage: http://wiki.github.com/tanordheim/freelancer-rails
|
32
|
+
* Example app:
|
33
|
+
|
34
|
+
== Requirements
|
35
|
+
|
36
|
+
* {freelancer}[http://rubygems.org/gems/freelancer]
|
37
|
+
|
38
|
+
== Installation
|
39
|
+
|
40
|
+
$ gem install freelancer-rails
|
41
|
+
|
42
|
+
== Note on Patches/Pull Requests
|
43
|
+
|
44
|
+
* Fork the project.
|
45
|
+
* Make your feature addition or bug fix.
|
46
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
47
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
48
|
+
* Send me a pull request. Bonus points for topic branches.
|
49
|
+
|
50
|
+
== License
|
51
|
+
|
52
|
+
Copyright (c) 2010 Trond Arve Nordheim. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "bundler"
|
3
|
+
require "rake/testtask"
|
4
|
+
require "rake/rdoctask"
|
5
|
+
|
6
|
+
# Gemcutter/Jeweler configuration
|
7
|
+
# ----------------------------------------------------------------------------
|
8
|
+
begin
|
9
|
+
|
10
|
+
require "jeweler"
|
11
|
+
|
12
|
+
Jeweler::Tasks.new do |gem|
|
13
|
+
|
14
|
+
gem.name = "freelancer-rails"
|
15
|
+
gem.summary = "Freelancer.com API for Ruby on Rails"
|
16
|
+
gem.description = "Ruby on Rails support for the Freelancer.com Ruby gem"
|
17
|
+
gem.email = "tanordheim@gmail.com"
|
18
|
+
gem.homepage = "http://github.com/tanordheim/freelancer-rails"
|
19
|
+
gem.authors = [ "Trond Arve Nordheim" ]
|
20
|
+
|
21
|
+
gem.files = FileList["[A-Z]*", "{app,config,lib,rails}/**/*"]
|
22
|
+
gem.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
|
23
|
+
|
24
|
+
gem.add_bundler_dependencies
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
Jeweler::GemcutterTasks.new
|
29
|
+
|
30
|
+
rescue LoadError
|
31
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Test setup
|
35
|
+
# ----------------------------------------------------------------------------
|
36
|
+
Rake::TestTask.new(:test) do |t|
|
37
|
+
t.libs << "lib" << "test"
|
38
|
+
t.ruby_opts << "-rubygems"
|
39
|
+
t.pattern = "test/**/*_test.rb"
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# RDoc setup
|
44
|
+
# ----------------------------------------------------------------------------
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
|
47
|
+
version = File.exists?("VERSION") ? File.read("VERSION") : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = "rdoc"
|
50
|
+
rdoc.title = "freelancer-rails #{version}"
|
51
|
+
rdoc.rdoc_files.include("README.rdoc")
|
52
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
# Rcov setup
|
57
|
+
# ----------------------------------------------------------------------------
|
58
|
+
begin
|
59
|
+
|
60
|
+
require "rcov/rcovtask"
|
61
|
+
|
62
|
+
Rcov::RcovTask.new do |test|
|
63
|
+
|
64
|
+
test.libs << "test"
|
65
|
+
test.pattern = "test/**/*_test.rb"
|
66
|
+
test.verbose = true
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
rescue LoadError
|
71
|
+
task :rcov do
|
72
|
+
abort "Rcov is not available. In order to run rcov, you must: sudo gem install rcov"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Task setups
|
77
|
+
# ----------------------------------------------------------------------------
|
78
|
+
task :test => :check_dependencies
|
79
|
+
task :default => :test
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Freelancer::Rails::AuthorizationsController < ApplicationController
|
2
|
+
|
3
|
+
include Freelancer::Rails::Controllers::Helpers
|
4
|
+
|
5
|
+
def new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
|
10
|
+
freelancer_client.set_callback_url(freelancer_oauth_callback_url + "?")
|
11
|
+
session["freelancer_oauth_request_token"] = freelancer_client.request_token.token
|
12
|
+
session["freelancer_oauth_request_secret"] = freelancer_client.request_token.secret
|
13
|
+
|
14
|
+
authorize_url = freelancer_client.request_token.authorize_url
|
15
|
+
redirect_to authorize_url
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def oauth_callback
|
20
|
+
|
21
|
+
request_token = session["freelancer_oauth_request_token"]
|
22
|
+
request_secret = session["freelancer_oauth_request_secret"]
|
23
|
+
|
24
|
+
freelancer_client.authorize_from_request(request_token, request_secret, params[:oauth_verifier])
|
25
|
+
session["freelancer_oauth_access_token"] = freelancer_client.access_token.token
|
26
|
+
session["freelancer_oauth_access_secret"] = freelancer_client.access_token.secret
|
27
|
+
|
28
|
+
redirect_to root_path
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<h1>Freelancer.com authorization required</h1>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
The application needs to request authorization from Freelancer.com on your behalf to be able to make requests against the Freelancer.com API.
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
You will now be redirected to Freelancer.com and asked to authorize this application to access the site on your behalf.
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<% form_tag freelancer_authorize_path do %>
|
12
|
+
<%= submit_tag "I understand, authorize this application" %>
|
13
|
+
<% end %>
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Freelancer
|
2
|
+
module Rails
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def api_token
|
8
|
+
configuration["api_token"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_secret
|
12
|
+
configuration["api_secret"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def sandbox_mode?
|
16
|
+
configuration["sandbox_mode"] == true
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def configuration_file
|
22
|
+
"#{RAILS_ROOT}/config/freelancer.yml"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Load the system configuration. This will try to load from the configuration
|
26
|
+
# file located in config/freelancer.yml first and use the configuration for the
|
27
|
+
# current environment. If that file can't be found, it will use the environment
|
28
|
+
# variables "FREELANCER_API_TOKEN", "FREELANCER_API_SECRET" and "FREELANCER_SANDBOX_MODE"
|
29
|
+
# instead.
|
30
|
+
def load!
|
31
|
+
|
32
|
+
if File.exists?(configuration_file)
|
33
|
+
@configuration = YAML.load(ERB.new(File.read(configuration_file)).result)[RAILS_ENV]
|
34
|
+
else
|
35
|
+
@configuration = {
|
36
|
+
"api_token" => ENV["FREELANCER_API_TOKEN"],
|
37
|
+
"api_secret" => ENV["FREELANCER_API_SECRET"],
|
38
|
+
"sandbox_mode" => ENV["FREELANCER_SANDBOX_MODE"]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def configuration
|
45
|
+
load! unless defined?(@configuration)
|
46
|
+
@configuration
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Freelancer
|
2
|
+
module Rails
|
3
|
+
module Controllers
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
# Returns the current instance of the Freelancer Client
|
7
|
+
def freelancer_client
|
8
|
+
@freelancer_client ||= Freelancer::Client.new(Freelancer::Rails::Configuration.api_token, Freelancer::Rails::Configuration.api_secret, :sandbox => Freelancer::Rails::Configuration.sandbox_mode?)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns true if the current user session contains an access token
|
12
|
+
def freelancer_access_token?
|
13
|
+
freelancer_access_token != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the current access token from the user session
|
17
|
+
def freelancer_access_token
|
18
|
+
session["freelancer_oauth_access_token"]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns true if the current user session contains an access secret
|
22
|
+
def freelancer_access_secret?
|
23
|
+
freelancer_access_secret != nil
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the current access secret from the user session
|
27
|
+
def freelancer_access_secret
|
28
|
+
session["freelancer_oauth_access_secret"]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Freelancer
|
2
|
+
module Rails
|
3
|
+
class Routes
|
4
|
+
|
5
|
+
def self.draw(map)
|
6
|
+
|
7
|
+
map.namespace(:freelancer) do |freelancer|
|
8
|
+
freelancer.sign_in "sign_in", :controller => "rails/authorizations", :action => "new"
|
9
|
+
freelancer.authorize "authorize", :controller => "rails/authorizations", :action => "create"
|
10
|
+
freelancer.oauth_callback "oauth_callback", :controller => "rails/authorizations", :action => "oauth_callback"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "freelancer-rails"
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: freelancer-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Trond Arve Nordheim
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-21 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 25
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 1
|
32
|
+
version: 0.1.1
|
33
|
+
type: :runtime
|
34
|
+
name: freelancer
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Ruby on Rails support for the Freelancer.com Ruby gem
|
38
|
+
email: tanordheim@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- Gemfile.lock
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
- VERSION
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
- Rakefile
|
54
|
+
- VERSION
|
55
|
+
- app/controllers/freelancer/rails/authorizations_controller.rb
|
56
|
+
- app/views/freelancer/rails/authorizations/new.html.erb
|
57
|
+
- lib/freelancer-rails.rb
|
58
|
+
- lib/freelancer-rails/configuration.rb
|
59
|
+
- lib/freelancer-rails/controllers/helpers.rb
|
60
|
+
- lib/freelancer-rails/routes.rb
|
61
|
+
- rails/init.rb
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_freelancer-rails.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/tanordheim/freelancer-rails
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: Freelancer.com API for Ruby on Rails
|
98
|
+
test_files:
|
99
|
+
- test/helper.rb
|
100
|
+
- test/test_freelancer-rails.rb
|