codebits 0.0.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.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg
5
+ .DS_Store
6
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in codebits.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+
2
+ Permission is hereby granted, free of charge, to any person obtaining
3
+ a copy of this software and associated documentation files (the
4
+ "Software"), to deal in the Software without restriction, including
5
+ without limitation the rights to use, copy, modify, merge, publish,
6
+ distribute, sublicense, and/or sell copies of the Software, and to
7
+ permit persons to whom the Software is furnished to do so, subject to
8
+ the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be
11
+ included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ Codebits API
2
+ ============
3
+
4
+ A dead simple ruby wrapper for the [SAPO Codebits API](http://codebits.eu)
5
+ as part of a project idea for codebits 2011 that we had at [Beta Branch](https://github.com/betabranch)
6
+
7
+ **Warning:** I haven't tested most methods yet, hope to do it soon.
8
+
9
+ ##Installation
10
+ ```ruby
11
+ gem install codebits
12
+ ```
13
+
14
+ ##Examples
15
+ ### Authentication
16
+ All methods require authentication, so go ahead and give him your codebits username and password.
17
+
18
+ ```ruby
19
+ client = Codebits::Client("username","password")
20
+ ```
21
+
22
+ ### Show a user
23
+
24
+ ```ruby
25
+ client.user(571)
26
+ => "{\"id\":\"575\",\"nick\":\"incude\",\"avatar\": ...}
27
+ ```
28
+
29
+ ##Copyright
30
+ Copyright (c) 2011 [Beta Branch](https://github.com/betabranch). [LICENSE](https://github.com/pnunocarvalho/codebits-api/blob/master/LICENSE)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "codebits"
6
+ s.version = "0.0.2"
7
+ s.authors = ["Pedro Carvalho"]
8
+ s.email = ["pnunovc@gmail.com"]
9
+ s.homepage = "http://github.com/betabranch/codebits-api"
10
+ s.summary = %q{Wrapper to the SAPO Codebits API}
11
+ s.description = %q{Wrapper to the SAPO Codebits API}
12
+
13
+ s.rubyforge_project = "codebits"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency 'faraday', '~> 0.7.4'
21
+ s.add_dependency 'multi_json'
22
+
23
+ # specify any dependencies here; for example:
24
+ # s.add_development_dependency "rspec"
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'codebits/user'
2
+ require 'codebits/session'
3
+ require 'codebits/talk'
4
+ require 'codebits/project'
5
+ require 'codebits/request'
6
+ require 'codebits/connection'
7
+
8
+ module Codebits
9
+ VERSION = "0.0.1"
10
+
11
+ class Client
12
+ attr_accessor :username, :password,
13
+ :auth, :conn
14
+
15
+ def initialize(user, password)
16
+ @username = user
17
+ @password = password
18
+ end
19
+
20
+ def authenticated?
21
+ !auth.nil?
22
+ end
23
+
24
+ def connected?
25
+ !conn.nil?
26
+ end
27
+
28
+ include Codebits::User
29
+ include Codebits::Session
30
+ include Codebits::Talk
31
+ include Codebits::Project
32
+ include Codebits::Request
33
+ include Codebits::Connection
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+ require 'multi_json'
3
+
4
+ module Codebits
5
+ module Connection
6
+ private
7
+ def connect
8
+ @conn = Faraday.new(:url => "https://services.sapo.pt") do |builder|
9
+ #builder.use Faraday::Response::Logger
10
+ builder.request :json
11
+ builder.adapter :net_http
12
+ end
13
+ authenticate
14
+ end
15
+
16
+ def authenticate
17
+ options = {:user => username, :password => password}
18
+ response = get("/Codebits/gettoken", options)
19
+ json = MultiJson.decode(response)
20
+ @auth = json['token']
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ module Codebits
2
+ module Project
3
+ def projects
4
+ get("/Codebits/projects")
5
+ end
6
+
7
+ def project(id)
8
+ get("/Codebits/project/#{id}")
9
+ end
10
+
11
+ def votes
12
+ get("/Codebits/votes")
13
+ end
14
+
15
+ def vote(id)
16
+ get("/Codebits/vote/#{id}")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module Codebits
2
+ module Request
3
+ def get(path, options={})
4
+ request(:get, path, options)
5
+ end
6
+
7
+ def put(path, options={})
8
+ request(:put, path, options)
9
+ end
10
+
11
+ private
12
+ def request(method, path, options)
13
+ connect if !connected?
14
+
15
+ options.merge!({:token => auth}) if authenticated?
16
+
17
+ response = conn.send(method) do |request|
18
+ request.url(path, options)
19
+ end
20
+
21
+ response.body
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module Codebits
2
+ module Session
3
+ def session(id)
4
+ get("/Codebits/session")
5
+ end
6
+
7
+ def calendar
8
+ get("/Codebits/calendar")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Codebits
2
+ module Talk
3
+ def submitions
4
+ get("/Codebits/calltalks")
5
+ end
6
+
7
+ def vote_up(id)
8
+ put("/Codebits/calluptalk/#{id}")
9
+ end
10
+
11
+ def vote_down(id)
12
+ put("/Codebits/calldowntalk/#{id}")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module Codebits
2
+ module User
3
+ def user(id)
4
+ get("/Codebits/user/#{id}")
5
+ end
6
+
7
+ def friends(id)
8
+ get("/Codebits/foaf/#{id}")
9
+ end
10
+
11
+ def add_friend(id)
12
+ put("/Codebits/foafadd/#{id}")
13
+ end
14
+
15
+ def reject_friend(id)
16
+ put("/Codebits/foafreject/#{id}")
17
+ end
18
+
19
+ def accepted(skill=nil)
20
+ get("/Codebits/users#{'/'+ skill if skill}")
21
+ end
22
+
23
+ def sessions(id)
24
+ get("/Codebits/usersessions/#{id}")
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebits
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pedro Carvalho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &19819800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19819800
25
+ - !ruby/object:Gem::Dependency
26
+ name: multi_json
27
+ requirement: &19819400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *19819400
36
+ description: Wrapper to the SAPO Codebits API
37
+ email:
38
+ - pnunovc@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - codebits.gemspec
49
+ - lib/codebits.rb
50
+ - lib/codebits/connection.rb
51
+ - lib/codebits/project.rb
52
+ - lib/codebits/request.rb
53
+ - lib/codebits/session.rb
54
+ - lib/codebits/talk.rb
55
+ - lib/codebits/user.rb
56
+ homepage: http://github.com/betabranch/codebits-api
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: codebits
76
+ rubygems_version: 1.8.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Wrapper to the SAPO Codebits API
80
+ test_files: []