duwanis-rubyku 0.0.2 → 0.0.3

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/lib/rubyku.rb CHANGED
@@ -1,22 +1,15 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
1
  # Just to make our requires at the top of the gem a little easier.
5
2
  require 'pathname'
6
- module Kernel
7
- def __DIR__
8
- Pathname(__FILE__).dirname.expand_path
9
- end
10
- end
3
+ $:.unshift(Pathname(__FILE__).dirname.expand_path)
11
4
 
12
5
  require 'net/http'
13
6
  require 'logger'
7
+ require 'rubygems'
8
+ require 'json'
14
9
  #rubyku requires
15
- require __DIR__ + 'rubyku/settings'
16
- require __DIR__ + 'rubyku/user'
17
- require __DIR__ + 'rubyku/credentials'
18
- require __DIR__ + 'rubyku/version'
19
-
20
- # The basic Rubyku exception.
21
- class RubykuError < RuntimeError
22
- end
10
+ require 'rubyku/settings'
11
+ require 'rubyku/errors'
12
+ require 'rubyku/user'
13
+ require 'rubyku/credentials'
14
+ require 'rubyku/version'
15
+ require 'rubyku/request'
@@ -32,6 +32,13 @@ module Rubyku
32
32
  @api_key
33
33
  end
34
34
 
35
+ ##
36
+ # returns the Jaiku-specified authentication string to attach
37
+ # to all requests (GETS) against the API.
38
+ def request_string
39
+ "?user=%s&personal_key=%s" % [self.username, self.api_key]
40
+ end
41
+
35
42
  class << self
36
43
 
37
44
  ##
@@ -97,7 +104,5 @@ module Rubyku
97
104
  end #end class << self
98
105
 
99
106
  end #end class
100
-
101
- class InvalidCredentialsError < RuntimeError
102
- end
107
+
103
108
  end
@@ -0,0 +1,11 @@
1
+ module Rubyku
2
+ # The basic Rubyku exception.
3
+ class Error < RuntimeError
4
+ end
5
+
6
+ class UserNotFoundError < Error
7
+ end
8
+
9
+ class InvalidCredentialsError < Error
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module Rubyku
2
+
3
+ class Request
4
+ class << self
5
+
6
+ def retrieve_json_object(url_path, jaiku_credentials)
7
+ url_path += jaiku_credentials.request_string
8
+
9
+ url = URI.parse(url_path)
10
+ req = Net::HTTP::Get.new(url.path)
11
+ res = Net::HTTP::Proxy(Rubyku::Settings.proxy_url, Rubyku::Settings.proxy_port) \
12
+ .start(url.host, url.port) {|http|
13
+ http.request(req)
14
+ }
15
+ JSON(res.body)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
@@ -21,7 +21,7 @@ module Rubyku
21
21
  end
22
22
 
23
23
  #initialize the default logger
24
- Rubyku::Settings.logger= Logger.new(__DIR__ + '../logs/rubyku.log')
24
+ Rubyku::Settings.logger= Logger.new('../logs/rubyku.log')
25
25
  Rubyku::Settings.logger.sev_threshold = Logger::INFO #DON'T set this line to DEBUG.
26
26
  # Do that in your own code if you want. Rubyku spews user information and such on DEBUG
27
27
  # And so it would be a very bad idea for DEBUG to make it into the gem.
data/lib/rubyku/user.rb CHANGED
@@ -26,7 +26,9 @@ module Rubyku
26
26
  # to the Jaiku servers.
27
27
  #
28
28
  def contacts(jaiku_credentials=Rubyku::Settings.jaiku_credentials)
29
+ log = Rubyku::Settings.logger
29
30
  unless @contacts
31
+ log.info("contacts for user #{@username} requested - attempting to fetch.")
30
32
  @contacts = User.fetchContacts(@username, jaiku_credentials)
31
33
  end
32
34
 
@@ -52,13 +54,23 @@ module Rubyku
52
54
  # to the Jaiku servers.
53
55
  #
54
56
  def fetch(username,jaiku_credentials=Rubyku::Settings.jaiku_credentials)
57
+ req_url = "http://%s.jaiku.com/json" % username
58
+ json = Rubyku::Request.retrieve_json_object(req_url, jaiku_credentials)
59
+ build_user_from_json(json)
60
+ end
61
+
62
+ def build_user_from_json(json)
63
+ user = Rubyku::User.new
64
+ user.nick= json['nick']
65
+ user.first_name= json['first_name']
66
+ user.last_name= json['last_name']
67
+ user.jaiku_url = json['url']
68
+ user.avatar_url = json['avatar']
69
+ user.contacts = json['contacts'] ? json['contacts'].map { |u| build_user_from_json(u)} : nil
55
70
 
71
+ user
56
72
  end
57
73
  end
58
-
59
-
60
- end
61
-
62
- class UserNotFoundError < RuntimeError
74
+
63
75
  end
64
76
  end
@@ -2,7 +2,7 @@ module Rubyku #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duwanis-rubyku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Morgan
@@ -11,8 +11,16 @@ cert_chain: []
11
11
 
12
12
  date: 2008-05-29 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">"
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ version:
16
24
  description: Rubyku is a library for accessing the public Jaiku API from a Ruby application.
17
25
  email: tommy.morgan@gmail.com
18
26
  executables: []
@@ -31,6 +39,8 @@ files:
31
39
  - lib/rubyku/credentials.rb
32
40
  - lib/rubyku/settings.rb
33
41
  - lib/rubyku/user.rb
42
+ - lib/rubyku/errors.rb
43
+ - lib/rubyku/request.rb
34
44
  - test/test_helper.rb
35
45
  - test/test_rubyku.rb
36
46
  has_rdoc: true