whatcd 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/whatcd.rb +41 -38
  2. metadata +10 -6
@@ -27,7 +27,7 @@ class WhatCD
27
27
  #
28
28
  # Returns a HTTParty::CookieHash. Raises an AuthError.
29
29
  def authenticate(username, password)
30
- body = { username: username, password: password }
30
+ body = { username: username, password: password, keeplogged: 1 }
31
31
  response = post '/login.php', body: body,
32
32
  follow_redirects: false
33
33
 
@@ -48,42 +48,6 @@ class WhatCD
48
48
  cookies.has_key? :session
49
49
  end
50
50
 
51
- # Public: Gets a Rippy quote.
52
- #
53
- # json - A Boolean indicating wether or not the return value should be
54
- # JSON (default: false).
55
- #
56
- # Returns a String or Hash.
57
- def rippy(json = false)
58
- raise AuthError unless authenticated?
59
-
60
- result = get '/ajax.php', query: { action: 'rippy', format: 'json' }
61
-
62
- if result.code != 200 || result['status'] == 'failure'
63
- raise(APIError)
64
- else
65
- json ? result : result['rippy']
66
- end
67
- end
68
-
69
- # Internal: Makes a request.
70
- #
71
- # action - An action name String.
72
- # query - A query Hash to send along (default: {}).
73
- #
74
- # Returns a Hash representing JSON. Raises an AuthError or APIError.
75
- def make_request(action, query = {})
76
- raise AuthError unless authenticated?
77
-
78
- result = get '/ajax.php', query: query.merge(action: action)
79
-
80
- if result.code != 200 || result['status'] == 'failure'
81
- raise(APIError)
82
- else
83
- result['response']
84
- end
85
- end
86
-
87
51
  # Public: Makes a request. The "method" name (capitalized!) is one of the
88
52
  # API actions (ajax.php?action=<this-bit>).
89
53
  #
@@ -111,7 +75,46 @@ class WhatCD
111
75
  #
112
76
  # Returns a String or Hash. Raises an AuthError or APIError.
113
77
  def const_missing(constant)
114
- constant == :Rippy ? rippy : super
78
+ # Rippy's response differs from the other respones.
79
+ constant == :Rippy ? rippy : make_request(constant.to_s.downcase)
80
+ end
81
+
82
+ private
83
+
84
+ # Internal: Makes a request.
85
+ #
86
+ # action - An action name String.
87
+ # query - A query Hash to send along (default: {}).
88
+ #
89
+ # Returns a Hash representing JSON. Raises an AuthError or APIError.
90
+ def make_request(action, query = {})
91
+ raise AuthError unless authenticated?
92
+
93
+ result = get '/ajax.php', query: query.merge(action: action)
94
+
95
+ if result.code != 200 || result['status'] == 'failure'
96
+ raise APIError
97
+ else
98
+ result['response']
99
+ end
100
+ end
101
+
102
+ # Internal: Gets a Rippy quote.
103
+ #
104
+ # json - A Boolean indicating wether or not the return value should be
105
+ # JSON (default: false).
106
+ #
107
+ # Returns a String or Hash.
108
+ def rippy(json = false)
109
+ raise AuthError unless authenticated?
110
+
111
+ result = get '/ajax.php', query: { action: 'rippy', format: 'json' }
112
+
113
+ if result.code != 200 || result['status'] == 'failure'
114
+ raise(APIError)
115
+ else
116
+ json ? result : result['rippy']
117
+ end
115
118
  end
116
119
  end
117
120
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatcd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &2154156560 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154156560
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: An API wrapper for What.cd's JSON API
26
31
  email:
27
32
  - paulbrickfeld@gmail.com
@@ -50,9 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
55
  version: '0'
51
56
  requirements: []
52
57
  rubyforge_project:
53
- rubygems_version: 1.8.13
58
+ rubygems_version: 1.8.23
54
59
  signing_key:
55
60
  specification_version: 3
56
61
  summary: An API wrapper for What.cd's JSON API
57
62
  test_files: []
58
- has_rdoc: