lc-api 0.8.3 → 0.8.4
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/lc-api/api.rb +5 -13
- data/lib/lc-api/resource.rb +14 -15
- data/lib/lc-api.rb +6 -1
- metadata +18 -2
data/lib/lc-api/api.rb
CHANGED
|
@@ -3,20 +3,12 @@ require 'httparty'
|
|
|
3
3
|
module LcApi
|
|
4
4
|
class API
|
|
5
5
|
class << self
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def method_missing method_name, *args
|
|
9
|
-
# method_name == "get"
|
|
10
|
-
# "args" === "message/1, {}"
|
|
11
|
-
# we are expecting "get" to be the method name here, but to be safe, we allow for
|
|
12
|
-
# missing methods other than "get", which we toss up to super
|
|
6
|
+
def method_missing(method_name, *args)
|
|
13
7
|
super(method_name, args) unless [:get].include? method_name
|
|
14
|
-
uri =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(uri = uri + "/#{param}") if (param)
|
|
19
|
-
HTTParty.get("#{uri}?key=#{LcApi.key}")
|
|
8
|
+
uri = LcApi.base_uri + args.shift
|
|
9
|
+
appends = ""
|
|
10
|
+
args.shift.each { |k,v| appends << "&#{k}=#{(v.is_a?(Array) ? v.join(",") : v)}" }
|
|
11
|
+
HTTParty.get("#{uri}?key=#{LcApi.key}#{appends}")
|
|
20
12
|
end
|
|
21
13
|
end
|
|
22
14
|
|
data/lib/lc-api/resource.rb
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
+
require 'active_support/inflector'
|
|
2
3
|
|
|
3
4
|
module LcApi
|
|
4
5
|
class Resource
|
|
5
6
|
class << self
|
|
6
7
|
|
|
7
|
-
def
|
|
8
|
-
uri = member_name
|
|
8
|
+
def find(id, options={})
|
|
9
|
+
uri = member_name
|
|
9
10
|
uri += "/#{id}" if id
|
|
10
|
-
|
|
11
|
+
puts "uri is: #{uri}"
|
|
12
|
+
parse_response(API.get(uri, options))
|
|
11
13
|
end
|
|
12
14
|
|
|
13
|
-
def all
|
|
14
|
-
uri = member_name
|
|
15
|
-
parse_response(API.get(uri), true)
|
|
15
|
+
def all(options={})
|
|
16
|
+
uri = member_name
|
|
17
|
+
parse_response(API.get(uri, options), true)
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def parse_response(response, multiple=false)
|
|
19
|
-
#puts "RESPONSE IS: #{response.parsed_response}"
|
|
20
21
|
case response.code.to_i
|
|
21
22
|
when 404
|
|
22
23
|
raise LcApi::API::NotFound.new(response), "Resource was not found"
|
|
@@ -43,9 +44,8 @@ module LcApi
|
|
|
43
44
|
new(attributes)
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
def member_name
|
|
47
|
-
|
|
48
|
-
name.split('::').last.downcase
|
|
47
|
+
def member_name
|
|
48
|
+
name.split('::').last.downcase.pluralize
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def define_attribute_methods(attributes)
|
|
@@ -60,23 +60,22 @@ module LcApi
|
|
|
60
60
|
attr_accessor :attributes
|
|
61
61
|
|
|
62
62
|
def initialize attributes = {}
|
|
63
|
-
# raise error if user attempts to initialize a Resource by calling new
|
|
64
63
|
raise Error, "#{self.class} is an abstract class and cannot be instantiated" if instance_of? Resource
|
|
65
64
|
@attributes = {}
|
|
66
|
-
self.attributes = attributes
|
|
65
|
+
self.attributes = attributes
|
|
67
66
|
end
|
|
68
67
|
|
|
69
|
-
def [](key)
|
|
68
|
+
def [](key)
|
|
70
69
|
@attributes[key]
|
|
71
70
|
end
|
|
72
71
|
|
|
73
|
-
def []=(key,value)
|
|
72
|
+
def []=(key,value)
|
|
74
73
|
@attributes[key] = value if self.respond_to?(key)
|
|
75
74
|
end
|
|
76
75
|
|
|
77
76
|
def attributes=(attributes = {})
|
|
78
77
|
attributes.each_pair do |key, val|
|
|
79
|
-
self[key] = val
|
|
78
|
+
self[key] = val
|
|
80
79
|
end
|
|
81
80
|
end
|
|
82
81
|
|
data/lib/lc-api.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lc-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2013-04-
|
|
13
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: httparty
|
|
@@ -28,6 +28,22 @@ dependencies:
|
|
|
28
28
|
- - ! '>='
|
|
29
29
|
- !ruby/object:Gem::Version
|
|
30
30
|
version: '0'
|
|
31
|
+
- !ruby/object:Gem::Dependency
|
|
32
|
+
name: active_support
|
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - ! '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 2.2.1
|
|
39
|
+
type: :runtime
|
|
40
|
+
prerelease: false
|
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
43
|
+
requirements:
|
|
44
|
+
- - ! '>='
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 2.2.1
|
|
31
47
|
description: A gem for consuming the LifeChurch.tv API
|
|
32
48
|
email: webmaster@lifechurch.tv
|
|
33
49
|
executables: []
|