flimb_api 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f70728efdc7911f9871600b44f58c2931fd6009
4
+ data.tar.gz: 4e7d712da8019ce834ebc883f4517c0601e58968
5
+ SHA512:
6
+ metadata.gz: 3f3998925cb75c3233df61dd4a5451c5fe1e22fd3474e0920cadd6ce0f842a78baf726d1f745939d8da3ffa615f56c1c11bc4e6dbe26feed3df90be65141d94c
7
+ data.tar.gz: b46e82616f7bfc628037e004f52f660d9414b0a0b656ac910e889b7b7d559518214c21b9ee813e131ba499829604e996615e061882c9ccf975f20c12f47a46dc
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.0.1
2
+
3
+ * Initial release
4
+ * Website, Alert, Scan
5
+
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'rspec'
8
+ end
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # FlimbApi gem
2
+
3
+ Flimb API client based on [ActiveResource](https://github.com/rails/activeresource).
4
+
5
+ ## Install
6
+
7
+ Add to Gemfile:
8
+
9
+ ```ruby
10
+ gem 'flimb_api'
11
+ ```
12
+
13
+ ## Use
14
+
15
+ ```ruby
16
+ website = FlimbApi::Website.last
17
+ website.enable_dnsbl = false
18
+ website.save
19
+
20
+ website.alerts.last
21
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => [:spec]
5
+ task :test => [:spec]
6
+
7
+ desc "Run all RSpec tests"
8
+ RSpec::Core::RakeTask.new(:spec)
data/flimb_api.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'flimb_api/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'flimb_api'
6
+ s.version = FlimbApi::VERSION::STRING
7
+ s.authors = 'Flimb'
8
+ s.email = 'contact@flimb.com'
9
+ s.homepage = 'https://github.com/flimb/flimb_api'
10
+ s.summary = 'Gem for accessing the Flimb REST web services'
11
+ s.description = 'Gem for accessing the Flimb REST web services'
12
+
13
+ s.rubyforge_project = 'flimb_api'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+
19
+ s.add_dependency('activesupport', ['>= 3.0.0'])
20
+ s.add_dependency('activeresource', ['>= 3.0.0'])
21
+ s.add_development_dependency 'rspec'
22
+ end
data/lib/flimb.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'flimb_api'
2
+
3
+ module Flimb
4
+ extend ActiveSupport::Autoload
5
+ end
data/lib/flimb_api.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'active_resource'
4
+
5
+ module FlimbApi
6
+ extend ActiveSupport::Autoload
7
+
8
+ Deprecator = ActiveSupport::Deprecation.new('1.0', name)
9
+
10
+ eager_autoload do
11
+ autoload :VERSION
12
+ autoload :Base
13
+ autoload :Alert
14
+ autoload :Scan
15
+ autoload :Website
16
+ end
17
+ end
18
+
19
+ ActiveSupport.run_load_hooks('flimb_api', FlimbApi)
@@ -0,0 +1,5 @@
1
+ module FlimbApi
2
+ class Alert < Base;
3
+ belongs_to :website, class_name: 'flimb_api/alert'
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require 'flimb_api/resource/countable'
2
+ require 'flimb_api/resource/paginated'
3
+
4
+ module FlimbApi
5
+ class Base < ActiveResource::Base
6
+ extend Resource::Countable
7
+ extend Resource::Paginated
8
+
9
+ self.include_root_in_json = true
10
+ self.headers['User-Agent'] = %W(
11
+ FlimbApi/#{FlimbApi::VERSION::STRING}
12
+ ActiveResource/#{ActiveResource::VERSION::STRING}
13
+ Ruby/#{RUBY_VERSION}).join(' ')
14
+ self.format = :json
15
+ self.prefix = '/api/'
16
+ self.site = 'https://flimb.com'
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module FlimbApi
2
+ module Resource
3
+ module Countable
4
+ def count(options = {})
5
+ get(:count, options).to_i
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module FlimbApi
2
+ PER_PAGE_DEFAULT = 100
3
+
4
+ module Resource
5
+ module Paginated
6
+ def find_each(*args)
7
+ find_in_batches(*args) do |batch|
8
+ batch.each { |record| yield record }
9
+ end
10
+ end
11
+
12
+ def find_in_batches(options = {})
13
+ per_page = options[:per_page] || PER_PAGE_DEFAULT
14
+ params = {per_page: per_page}.merge(options[:params] || {})
15
+ page = 1
16
+ loop do
17
+ items = all(params: params.merge(page: page))
18
+ return unless items.any?
19
+ yield items
20
+ return if items.count < per_page
21
+ page += 1
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module FlimbApi
2
+ class Scan < Base
3
+ has_many :alerts, class_name: 'flimb_api/alert'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module FlimbApi
2
+ module VERSION
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+ PRE = 'pre'
7
+
8
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module FlimbApi
2
+ class Website < Base
3
+ has_many :alerts, class_name: 'flimb_api/alert'
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe FlimbApi do
4
+
5
+ http_options = { 'Accept' => 'application/json',
6
+ 'User-Agent' => FlimbApi::Base.headers['User-Agent'] }
7
+
8
+ it 'returns websites' do
9
+ websites = [{ id: 1, name: 'example.com' }, { id: 2, name: 'example.org' }]
10
+ ActiveResource::HttpMock.respond_to do |mock|
11
+ mock.get '/api/websites.json', http_options, websites.to_json
12
+ mock.get '/api/websites/1.json', http_options, websites.first.to_json
13
+ end
14
+ FlimbApi::Website.all.size.should == 2
15
+ FlimbApi::Website.find(1).name.should == 'example.com'
16
+ end
17
+
18
+ it 'returns alerts' do
19
+ website = { id: 1, name: 'example.com' }
20
+ alerts = [{ id: 1, source: 'Dnsbl', state: 'unresolved' }]
21
+ ActiveResource::HttpMock.respond_to do |mock|
22
+ mock.get '/api/websites/1.json', http_options, website.to_json
23
+ mock.get '/api/alerts.json?website_id=1', http_options, alerts.to_json
24
+ end
25
+ FlimbApi::Website.find(1).alerts.first.source.should == 'Dnsbl'
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'flimb_api'
4
+
5
+ FlimbApi::Base.user = nil
6
+ FlimbApi::Base.password = nil
7
+
8
+ RSpec.configure do |config|
9
+ # == Mock Framework
10
+ #
11
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
12
+ #
13
+ # config.mock_with :mocha
14
+ # config.mock_with :flexmock
15
+ # config.mock_with :rr
16
+ config.mock_with :rspec
17
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flimb_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Flimb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activeresource
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Gem for accessing the Flimb REST web services
56
+ email: contact@flimb.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - .gitignore
62
+ - CHANGELOG.md
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - flimb_api.gemspec
67
+ - lib/flimb.rb
68
+ - lib/flimb_api.rb
69
+ - lib/flimb_api/alert.rb
70
+ - lib/flimb_api/base.rb
71
+ - lib/flimb_api/resource/countable.rb
72
+ - lib/flimb_api/resource/paginated.rb
73
+ - lib/flimb_api/scan.rb
74
+ - lib/flimb_api/version.rb
75
+ - lib/flimb_api/website.rb
76
+ - spec/lib/flimb_api/app_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/flimb/flimb_api
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>'
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.1
95
+ requirements: []
96
+ rubyforge_project: flimb_api
97
+ rubygems_version: 2.0.14
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Gem for accessing the Flimb REST web services
101
+ test_files:
102
+ - spec/lib/flimb_api/app_spec.rb
103
+ - spec/spec_helper.rb