mashery_rails 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'http://rubygems.org'
3
3
  gem 'activesupport', ">= 3.1.0"
4
4
  gem 'rest-client'
5
5
  gem 'json'
6
+ gem 'virtus'
6
7
 
7
8
  group :test do
8
9
  gem 'timecop'
data/Gemfile.lock CHANGED
@@ -170,6 +170,9 @@ GEM
170
170
  concord (~> 0.1.1)
171
171
  equalizer (~> 0.0.7)
172
172
  parser (~> 2.0.0.pre6)
173
+ virtus (0.5.5)
174
+ backports (~> 3.3)
175
+ descendants_tracker (~> 0.0.1)
173
176
  yard (0.8.7.1)
174
177
  yard-spellcheck (0.1.5)
175
178
  ffi-hunspell (~> 0.2)
@@ -210,6 +213,7 @@ DEPENDENCIES
210
213
  simplecov (~> 0.7.1)
211
214
  terminal-notifier-guard (~> 1.5.3)
212
215
  timecop
216
+ virtus
213
217
  yard (~> 0.8.7)
214
218
  yard-spellcheck (~> 0.1.5)
215
219
  yardstick (~> 0.9.7)!
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # mashery_rails
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/mashery_rails.png)](http://badge.fury.io/rb/mashery_rails)
3
4
  [![Coverage Status](https://coveralls.io/repos/farleyknight/mashery_rails/badge.png)](https://coveralls.io/r/farleyknight/mashery_rails)
4
5
  [![Build Status](https://travis-ci.org/farleyknight/mashery_rails.png?branch=master)](https://travis-ci.org/farleyknight/mashery_rails)
5
6
  [![Code Climate](https://codeclimate.com/github/farleyknight/mashery_rails.png)](https://codeclimate.com/github/farleyknight/mashery_rails)
@@ -42,7 +43,12 @@ Note this doesn't distinguish between development, testing, production, etc. If
42
43
 
43
44
  ## JSON-RPC API
44
45
 
45
- The central data objects are all listed on the [RPC API documentation page](http://support.mashery.com/docs/read/mashery_api/20/API_Objects), and should be supported. However, [fetching objects](http://support.mashery.com/docs/read/mashery_api/20/Fetching_Objects) are the main & typically only supported method for each of these objects. If you feel you want to support more methods, feel free to create a pull request.
46
+ The central data objects are all listed on the
47
+ [RPC API documentation page](http://support.mashery.com/docs/read/mashery_api/20/API_Objects),
48
+ and should be supported. However,
49
+ [fetching objects](http://support.mashery.com/docs/read/mashery_api/20/Fetching_Objects)
50
+ are the main & typically only supported method for each of these objects. If you would like more API methods,
51
+ don't be shy! Create a pull request and it'll probably get merged within a day.
46
52
 
47
53
  ### `all`
48
54
 
@@ -122,4 +128,74 @@ Mashery::Member.page(10)
122
128
 
123
129
  ## REST API
124
130
 
125
- Mashery's REST API are mostly calls based on service objects.
131
+ Mashery's REST API are pulling statistics about Services. As such, these calls are invoked via the `Service` API object
132
+
133
+ ### `Service#activity`
134
+
135
+ Maps to the [CallsDeveloperActivityForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsDeveloperActivityForService)
136
+ call.
137
+
138
+ ```ruby
139
+ service = Mashery::Service.where(key: "my_service_id")
140
+ service.activity #=>
141
+ ```
142
+
143
+ ### `Service#errorcodes`
144
+
145
+ Maps to the [CallsErrorcodesForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsErrorcodesForService)
146
+ call.
147
+
148
+ ```ruby
149
+ service = Mashery::Service.where(key: "my_service_id")
150
+ service.errorcodes #=>
151
+ ```
152
+
153
+ ### `Service#errorcount`
154
+
155
+ Maps to the [CallsErrorcountByMethodForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsErrorcountByMethodForService)
156
+ call.
157
+
158
+ ```ruby
159
+ service = Mashery::Service.where(key: "my_service_id")
160
+ service.errorcount #=>
161
+ ```
162
+
163
+ ### `Service#latency`
164
+
165
+ Maps to the [CallsLatencyForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsLatencyForService)
166
+ call.
167
+
168
+ ```ruby
169
+ service = Mashery::Service.where(key: "my_service_id")
170
+ service.latency #=>
171
+ ```
172
+
173
+ ### `Service#latency_by_method`
174
+
175
+ Maps to the [CallsLatencyByMethodForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsLatencyByMethodForService)
176
+ call.
177
+
178
+ ```ruby
179
+ service = Mashery::Service.where(key: "my_service_id")
180
+ service.latency_by_method #=>
181
+ ```
182
+
183
+ ### `Service#methods`
184
+
185
+ Maps to the [CallsMethodsForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsMethodsForService)
186
+ call.
187
+
188
+ ```ruby
189
+ service = Mashery::Service.where(key: "my_service_id")
190
+ service.methods #=>
191
+ ```
192
+
193
+ ### `Service#volume_by_hour`
194
+
195
+ Maps to the [CallsMedianVolumeByHourForService](http://support.mashery.com/docs/read/mashery_api/20_reporting/REST_Resources#CallsMedianVolumeByHourForService)
196
+ call.
197
+
198
+ ```ruby
199
+ service = Mashery::Service.where(key: "my_service_id")
200
+ service.volume_by_hour #=>
201
+ ```
@@ -0,0 +1,9 @@
1
+ require 'rails/generators'
2
+
3
+ class MasheryInstallGenerator < Rails::Generators::Base
4
+ desc "Create mashery.yml config file"
5
+ def create_initializer_file
6
+ config = %q{---\nsite_id: '123'\nkey: "abc"\nsecret: "xyz"\nhost: "api.mashery.com"}
7
+ create_file "config/mashery.yml", config
8
+ end
9
+ end
data/lib/mashery/key.rb CHANGED
@@ -1,7 +1,19 @@
1
1
  module Mashery
2
2
  class Key < RpcClient::Base
3
- attr_accessor(:id, :created, :updated, :service_key, :apikey, :username, :status,
4
- :rate_limit_ceiling, :qps_limit_ceiling, :rate_limit_exempt, :qps_limit_exempt,
5
- :required_referer, :secret, :limits, :object_type)
3
+ attribute :id, Fixnum
4
+ attribute :created, DateTime
5
+ attribute :updated, DateTime
6
+ attribute :service_key, String
7
+ attribute :apikey, String
8
+ attribute :username, String
9
+ attribute :status, String
10
+ attribute :rate_limit_ceiling, Fixnum
11
+ attribute :qps_limit_ceiling, Fixnum
12
+ attribute :rate_limit_exempt, Fixnum
13
+ attribute :qps_limit_exempt, Fixnum
14
+ attribute :required_referer, Fixnum
15
+ attribute :secret, Fixnum
16
+ attribute :object_type, String
17
+ attribute :limits, Array
6
18
  end
7
19
  end
@@ -1,8 +1,28 @@
1
1
  module Mashery
2
2
  class Member < RpcClient::Base
3
- attr_accessor(:created, :updated, :username, :email, :display_name,
4
- :uri, :blog, :im, :imsvc, :phone, :company, :address1, :address2,
5
- :locality, :region, :postal_code, :country_code, :first_name, :last_name,
6
- :registration_ipaddr, :area_status, :external_id, :passwd_new, :object_type)
3
+ attribute :username, String
4
+ attribute :created, DateTime
5
+ attribute :updated, DateTime
6
+ attribute :email, String
7
+ attribute :display_name, String
8
+ attribute :url, String
9
+ attribute :blog, String
10
+ attribute :im, String
11
+ attribute :imsvc, String
12
+ attribute :phone, String
13
+ attribute :company, String
14
+ attribute :address1, String
15
+ attribute :address2, String
16
+ attribute :locality, String
17
+ attribute :region, String
18
+ attribute :postal_code, String
19
+ attribute :country_code, String
20
+ attribute :first_name, String
21
+ attribute :last_name, String
22
+ attribute :registration_ipaddr, String
23
+ attribute :area_status, String
24
+ attribute :external_id, String
25
+ attribute :passwd_new, String
26
+ attribute :object_type, String
7
27
  end
8
28
  end
@@ -4,21 +4,21 @@ module Mashery
4
4
  Query.new(query_params).url
5
5
  end
6
6
 
7
- def activity(activity_type, service_id, options)
7
+ def call(activity_type, service_id, options)
8
8
  if activity_type == "developer_activity"
9
- developer_activity(service_id, options)
9
+ query_options = {service_id: service_id, resource: "developer_activity"}.merge(options)
10
+ query = Query.new(query_options)
11
+ perform_query(query)
12
+ elsif activity_type == "errorcodes"
13
+ query_options = {service_id: service_id, resource: "errorcodes"}.merge(options)
14
+ query = Query.new(query_options)
15
+ perform_query(query)
10
16
  else
11
17
  raise "No such activity type!"
12
18
  end
13
19
  end
14
20
 
15
- def developer_activity_query(service_id, options)
16
- query_options = {service_id: service_id, resource: "developer_activity"}.merge(options)
17
- Query.new(query_options)
18
- end
19
-
20
- def developer_activity(service_id, options)
21
- query = developer_activity_query(service_id, options)
21
+ def perform_query(query)
22
22
  response = ::RestClient.get(query.url)
23
23
 
24
24
  if query.format == "json" or query.format == "csv"
@@ -1,11 +1,9 @@
1
+ require 'virtus'
2
+
1
3
  module Mashery
2
4
  class RpcClient
3
5
  class Base
4
- def initialize(attributes)
5
- attributes.each do |key, value|
6
- send("#{key}=", value)
7
- end
8
- end
6
+ include Virtus
9
7
 
10
8
  def self.count
11
9
  default_query.items(1).to_json["result"]["total_items"]
@@ -1,9 +1,24 @@
1
1
  module Mashery
2
2
  class Service < RpcClient::Base
3
- attr_accessor :service_key, :name, :limits, :created, :updated, :object_type
3
+ attribute :service_key, String
4
+ attribute :name, String
5
+ attribute :limits, Hash
6
+ attribute :created, DateTime
7
+ attribute :updated, DateTime
8
+ attribute :object_type, String
4
9
 
5
10
  def activity(options = {})
6
- Mashery.rest.activity("developer_activity", service_key, start_date: 1.day.ago, end_date: 0.days.ago)
11
+ Mashery.rest.call("developer_activity", service_key, {
12
+ # TODO: For API purposes, these values probably shouldn't be hard-coded
13
+ start_date: 1.day.ago, end_date: 0.days.ago
14
+ }.merge(options))
15
+ end
16
+
17
+ def errorcodes(options = {})
18
+ Mashery.rest.call("errorcodes", service_key, {
19
+ # TODO: For API purposes, these values probably shouldn't be hard-coded
20
+ start_date: 1.day.ago, end_date: 0.days.ago
21
+ }.merge(options))
7
22
  end
8
23
  end
9
24
  end
@@ -1,3 +1,3 @@
1
1
  module Mashery
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.8"
3
3
  end
data/lib/mashery.rb CHANGED
@@ -50,6 +50,6 @@ module Mashery
50
50
  end
51
51
 
52
52
  def self.activity(activity_type, service_id, options)
53
- Mashery.rest.activity(activity_type, service_id, options)
53
+ Mashery.rest.call(activity_type, service_id, options)
54
54
  end
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module Mashery
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mashery_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -86,6 +86,7 @@ files:
86
86
  - config/reek.yml
87
87
  - config/rubocop.yml
88
88
  - config/yardstick.yml
89
+ - lib/generators/mashery_install_generator.rb
89
90
  - lib/mashery.rb
90
91
  - lib/mashery/config.rb
91
92
  - lib/mashery/exceptions.rb
@@ -133,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  segments:
135
136
  - 0
136
- hash: -1487635472478857244
137
+ hash: -3439431454915658580
137
138
  required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  none: false
139
140
  requirements: