ruby_desk 0.0.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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ahmed ElDawy
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,18 @@
1
+ = ruby_desk
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2010 Ahmed ElDawy. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ruby_desk"
8
+ gem.summary = %Q{Wrapper for oDesk APIs in Ruby}
9
+ gem.description = %Q{A gem that works as an interface for oDesk APIs that can be used for both desktop and web applications}
10
+ gem.email = "ahmed.eldawy@badrit.com"
11
+ gem.homepage = "http://github.com/aseldawy/ruby_desk"
12
+ gem.authors = ["Ahmed ElDawy"]
13
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "ruby_desk #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/ruby_desk.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'digest/md5'
2
+
3
+ class RubyDesk
4
+ ODESK_API_URL = "www.odesk.com/api/"
5
+ ODESK_AUTH_URL = "www.odesk.com/services/api/auth/"
6
+ DEFAULT_OPTIONS = {:secure=>true, :sign=>true, :format=>'xml'}
7
+
8
+ def initialize(api_key=nil, api_secret=nil)
9
+ @api_key = api_key
10
+ @api_secret = api_secret
11
+ @api_key = "991ac77f4c202873b0ab88f11762370c"
12
+ @api_secret = "c3382d5902e5a7b0"
13
+ end
14
+
15
+ # Sign the given parameters and updates the given
16
+ def sign(params)
17
+ # sort parameters by its names (keys)
18
+ sorted_params = params.sort { |a, b| a.to_s <=> b.to_s}
19
+
20
+ # concatenate secret with names, values
21
+ concatenated = @api_secret + sorted_params.to_s
22
+
23
+ # Calculate md5 of concatenated string
24
+ md5 = Digest::MD5.hexdigest(concatenated)
25
+
26
+ # Return the calculated value as the signature
27
+ md5
28
+ end
29
+
30
+ # Returns the correct URL to go to to invoke the given api
31
+ # path: the path of the API to call. e.g. 'auth'
32
+ # params: a hash of parameters that needs to be appended
33
+ # options:
34
+ # * :secure=>false: Whether a secure connection is required or not.
35
+ # * :sign=>true: Whether you need to sign the parameters or not
36
+ def get_api_url(path, params = {}, options = {})
37
+ options = DEFAULT_OPTIONS.merge(options)
38
+ params[:api_sig] = sign(params) if options[:sign]
39
+ {:url=>"http#{options[:secure]? 's' : ''}://" + ODESK_API_URL + path + "." + options[:format],
40
+ :params=> params, :method=>options[:method]}
41
+ end
42
+
43
+ # Returns the URL that authenticates the application for the current user
44
+ def auth_url
45
+ params = {:api_key=>@api_key}
46
+ params[:api_sig] = sign(params)
47
+ "https://"+ODESK_AUTH_URL+"?"+params.to_a.map{|pair| pair.join '='}.join('&')
48
+ end
49
+
50
+ # return the URL that logs user out of odesk applications
51
+ def logout_url
52
+ "https://"+ODESK_AUTH_URL
53
+ end
54
+
55
+ # Returns an authentication frob.
56
+ # Parameters
57
+ # * frob
58
+ # * api_key
59
+ # * api_sig
60
+ #
61
+ # Return Data
62
+ # * token
63
+ def get_token_url(frob, options={})
64
+ get_api_url 'auth/v1/keys/tokens', {:frob=>frob, :api_key=>@api_key}, options.merge(:method=>:post)
65
+ end
66
+
67
+ # Returns an authentication frob.
68
+ #Parameters
69
+ # * api_key
70
+ # * api_sig
71
+ #
72
+ #Return Data
73
+ # * frob
74
+
75
+ def get_frob_url(options={})
76
+ get_api_url 'auth/v1/keys/frobs', {:api_key=>@api_key}, options.merge(:method=>:post)
77
+ end
78
+
79
+ #Returns the authenticated user associated with the given authorization token.
80
+ # Parameters
81
+ #
82
+ # * api_key
83
+ # * api_sig
84
+ # * api_token
85
+ #
86
+ # Return Data
87
+ #
88
+ # * token
89
+ def check_token_url(api_token, options={})
90
+ get_api_url 'auth/v1/keys/token', {:api_key=>@api_key, :api_token=>@api_token}, options.merge(:method=>:get)
91
+ end
92
+
93
+ def revoke_token_url(api_token, options={})
94
+ get_api_url 'auth/v1/keys/token', {:api_key=>@api_key, :api_token=>@api_token}, options.merge(:method=>:delete)
95
+ end
96
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'ruby_desk'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/test/test.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'open-uri'
5
+ require 'ruby_desk'
6
+ require 'rubygems'
7
+ require 'json'
8
+
9
+ rd = RubyDesk.new
10
+
11
+ get_frob = rd.get_frob_url(:format=>'json')
12
+
13
+ url = URI.parse(get_frob[:url])
14
+
15
+ http = Net::HTTP.new(url.host, url.port)
16
+ http.use_ssl = true
17
+ path = url.path
18
+
19
+ data = get_frob[:params].to_a.map{|pair| pair.join '='}.join('&')
20
+ headers = {
21
+ 'Content-Type' => 'application/x-www-form-urlencoded'
22
+ }
23
+
24
+ resp, data = http.post(path, data, headers)
25
+
26
+ json = JSON.parse(data)
27
+ frob = json['frob']
28
+
29
+ get_token = rd.get_token_url(frob, :format=>'json')
30
+
31
+ url = URI.parse(get_token[:url])
32
+
33
+ path = url.path
34
+
35
+ data = get_frob[:params].to_a.map{|pair| pair.join '='}.join('&')
36
+ headers = {
37
+ 'Content-Type' => 'application/x-www-form-urlencoded'
38
+ }
39
+
40
+ resp, data = http.post(path, data, headers)
41
+
42
+ json = JSON.parse(data)
43
+
44
+ puts json.inspect
45
+
46
+ puts open('https://www.odesk.com/api/team/v1/teamrooms')
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRubyDesk < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_desk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed ElDawy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-05 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A gem that works as an interface for oDesk APIs that can be used for both desktop and web applications
17
+ email: ahmed.eldawy@badrit.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/ruby_desk.rb
33
+ - test/helper.rb
34
+ - test/test_ruby_desk.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/aseldawy/ruby_desk
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Wrapper for oDesk APIs in Ruby
63
+ test_files:
64
+ - test/test_ruby_desk.rb
65
+ - test/helper.rb
66
+ - test/test.rb