mashery 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +24 -0
- data/VERSION +1 -1
- data/lib/mashery.rb +1 -0
- data/lib/mashery/query.rb +63 -0
- data/mashery.gemspec +5 -4
- metadata +10 -4
data/README.textile
CHANGED
@@ -25,3 +25,27 @@ Before you can successfully call an API method, you must set these environment v
|
|
25
25
|
bc. $ export MASHERY_SITE_ID=666
|
26
26
|
$ export MASHERY_API_KEY=cafebebedeadbeefcafebebedeadbeef
|
27
27
|
$ export MASHERY_SHARED_SECRET=blahblahblah
|
28
|
+
|
29
|
+
h3. Querying objects
|
30
|
+
|
31
|
+
The Mashery API supports querying the following types of objects: "members":http://support.mashery.com/docs/mashery_api/member/, "applications":http://support.mashery.com/docs/mashery_api/application/, "keys":http://support.mashery.com/docs/mashery_api/key/, "services":http://support.mashery.com/docs/mashery_api/service/, and "roles":http://support.mashery.com/docs/mashery_api/role/.
|
32
|
+
|
33
|
+
To perform a query, construct a Query object for the type of object you want to query:
|
34
|
+
|
35
|
+
bc. query = Mashery::Query.new('members')
|
36
|
+
members = query.fetch_all
|
37
|
+
|
38
|
+
The @fetch_all@ method will automatically paginate through the results for you. You can also control this yourself with the @page@ parameter and @execute@:
|
39
|
+
|
40
|
+
bc. query = Mashery::Query.new('members', :page => 2)
|
41
|
+
result = query.execute
|
42
|
+
items = result['items']
|
43
|
+
|
44
|
+
(Or, use the @items@ method, which combines @execute@ and @result['items']@ -- however, this does not return result set metadata, like current page and total pages.)
|
45
|
+
|
46
|
+
The default will return all fields (e.g., @SELECT * FROM members@). To control this, specify the @:fields@ parameter.
|
47
|
+
|
48
|
+
To control which records are returned, specify the @:where@ parameter.
|
49
|
+
|
50
|
+
bc. query = Mashery::Query.new('members', :where => 'username = "Jeff"'
|
51
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/lib/mashery.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Mashery
|
2
|
+
class Query
|
3
|
+
OBJECT_TYPES = ['members', 'keys', 'services', 'roles', 'applications']
|
4
|
+
DEFAULT_QUERIES_PER_SECOND = 2
|
5
|
+
|
6
|
+
attr_reader :object_type, :fields
|
7
|
+
attr_accessor :page
|
8
|
+
|
9
|
+
def initialize(object_type, options={})
|
10
|
+
if !OBJECT_TYPES.include?(object_type)
|
11
|
+
raise "Invalid object type. '#{object_type}' must be in #{OBJECT_TYPES.inspect}"
|
12
|
+
end
|
13
|
+
|
14
|
+
@object_type = object_type
|
15
|
+
|
16
|
+
if options[:fields]
|
17
|
+
@fields = options[:fields]
|
18
|
+
else
|
19
|
+
@fields = "*"
|
20
|
+
end
|
21
|
+
|
22
|
+
@where = options[:where]
|
23
|
+
@page = options[:page]
|
24
|
+
end
|
25
|
+
|
26
|
+
def page_clause
|
27
|
+
"PAGE #{@page}" if @page
|
28
|
+
end
|
29
|
+
|
30
|
+
def where_clause
|
31
|
+
"WHERE #{@where}" if @where
|
32
|
+
end
|
33
|
+
|
34
|
+
def query_string
|
35
|
+
"SELECT #{fields} FROM #{object_type} #{where_clause} #{page_clause}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute
|
39
|
+
Mashery.client.call_remote('object.query', query_string)
|
40
|
+
end
|
41
|
+
|
42
|
+
def items
|
43
|
+
execute['items']
|
44
|
+
end
|
45
|
+
|
46
|
+
# Page through the results. Due heavy use of the API, this method
|
47
|
+
# takes a qps parameter to control how often the API is called.
|
48
|
+
def fetch_all(qps=DEFAULT_QUERIES_PER_SECOND)
|
49
|
+
response = execute
|
50
|
+
items = response['items']
|
51
|
+
|
52
|
+
while response['current_page'] < response['total_pages']
|
53
|
+
self.page = response['current_page'] + 1
|
54
|
+
response = execute
|
55
|
+
items = items + response['items']
|
56
|
+
|
57
|
+
sleep(1.0/DEFAULT_QUERIES_PER_SECOND)
|
58
|
+
end
|
59
|
+
|
60
|
+
return items
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/mashery.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mashery}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Brian Moseley"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-26}
|
13
13
|
s.email = %q{brian@outside.in}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/mashery/exceptions.rb",
|
29
29
|
"lib/mashery/key.rb",
|
30
30
|
"lib/mashery/member.rb",
|
31
|
+
"lib/mashery/query.rb",
|
31
32
|
"lib/mashery/role.rb",
|
32
33
|
"mashery.gemspec",
|
33
34
|
"tasks/mashery.thor"
|
@@ -35,14 +36,14 @@ Gem::Specification.new do |s|
|
|
35
36
|
s.homepage = %q{http://github.com/outsidein/mashery-rb}
|
36
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
37
38
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
39
40
|
s.summary = %q{A Ruby library for the Mashery API}
|
40
41
|
|
41
42
|
if s.respond_to? :specification_version then
|
42
43
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
44
|
s.specification_version = 3
|
44
45
|
|
45
|
-
if Gem::Version.new(Gem::
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
47
|
else
|
47
48
|
end
|
48
49
|
else
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mashery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Brian Moseley
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-26 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -40,6 +41,7 @@ files:
|
|
40
41
|
- lib/mashery/exceptions.rb
|
41
42
|
- lib/mashery/key.rb
|
42
43
|
- lib/mashery/member.rb
|
44
|
+
- lib/mashery/query.rb
|
43
45
|
- lib/mashery/role.rb
|
44
46
|
- mashery.gemspec
|
45
47
|
- tasks/mashery.thor
|
@@ -53,23 +55,27 @@ rdoc_options:
|
|
53
55
|
require_paths:
|
54
56
|
- lib
|
55
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
56
59
|
requirements:
|
57
60
|
- - ">="
|
58
61
|
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
59
63
|
segments:
|
60
64
|
- 0
|
61
65
|
version: "0"
|
62
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
63
68
|
requirements:
|
64
69
|
- - ">="
|
65
70
|
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
66
72
|
segments:
|
67
73
|
- 0
|
68
74
|
version: "0"
|
69
75
|
requirements: []
|
70
76
|
|
71
77
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.3.
|
78
|
+
rubygems_version: 1.3.7
|
73
79
|
signing_key:
|
74
80
|
specification_version: 3
|
75
81
|
summary: A Ruby library for the Mashery API
|