drone_api 0.1.0
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +5 -0
- data/drone_api.gemspec +19 -0
- data/lib/drone_api/client.rb +53 -0
- data/lib/drone_api/request.rb +13 -0
- data/lib/drone_api/strike.rb +54 -0
- data/lib/drone_api/version.rb +3 -0
- data/lib/drone_api.rb +19 -0
- data/spec/drone_api_spec.rb +39 -0
- data/spec/spec_helper.rb +9 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Bryan Fordham
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# DroneApi
|
|
2
|
+
|
|
3
|
+
Library to access the DroneApi API
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'drone_api'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install drone_api
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
First, you need a Client
|
|
22
|
+
|
|
23
|
+
> require 'drone_api'
|
|
24
|
+
> client = DroneApi::Client.new
|
|
25
|
+
|
|
26
|
+
You can also call DroneApi.new:
|
|
27
|
+
|
|
28
|
+
> require 'drone_api'
|
|
29
|
+
> client = DroneApi.new
|
|
30
|
+
|
|
31
|
+
If you just want all of the strikes:
|
|
32
|
+
> strikes = client.all
|
|
33
|
+
|
|
34
|
+
It is an array of Strike instances.
|
|
35
|
+
|
|
36
|
+
In order to find a specific strike, you can pass in the number.
|
|
37
|
+
|
|
38
|
+
> strike = client.find 1
|
|
39
|
+
|
|
40
|
+
This will return a single strike (or nil, if nothing is found). You can also pass in an attribute name and value, and it will return a list containing all strikes matching that parameter.
|
|
41
|
+
|
|
42
|
+
> x = c.find :bureau_id => 'YEM001' # Returns an array of 1 element
|
|
43
|
+
> six_deaths = c.find :deaths => 6
|
|
44
|
+
|
|
45
|
+
There are some find_by_X methods. They are based on the attribute names of the Strike class. (If you're familiar with Rails, think model find methods). The following are equale to the examples above:
|
|
46
|
+
|
|
47
|
+
> x = c.find_by_bureau_id 'YEM001'
|
|
48
|
+
> six_deaths = c.find_by_deaths 6
|
|
49
|
+
|
|
50
|
+
One think to keep in mind. All these finders return an array *except* find_by_number. This returns a single instance, just as Client.find does.
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
## Contributing
|
|
54
|
+
|
|
55
|
+
I'm open to all suggestions.
|
|
56
|
+
|
|
57
|
+
1. Fork it
|
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
59
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/drone_api.gemspec
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/drone_api/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Bryan Fordham"]
|
|
6
|
+
gem.email = ["bfordham@gmail.com"]
|
|
7
|
+
gem.description = %q{Library to access the DroneApi API}
|
|
8
|
+
gem.summary = %q{Allows retrieving drone strike info, and basic searching.}
|
|
9
|
+
gem.homepage = "https://github.com/bfordham/drone_api"
|
|
10
|
+
|
|
11
|
+
gem.files = `git ls-files`.split($\)
|
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
14
|
+
gem.name = "drone_api"
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = DroneApi::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.13'
|
|
19
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module DroneApi
|
|
2
|
+
class Client
|
|
3
|
+
|
|
4
|
+
# Returns entire list of strikes
|
|
5
|
+
#
|
|
6
|
+
def all
|
|
7
|
+
@cache ||= Request.get('/data')
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Locates a specific strike by number
|
|
12
|
+
def find(params)
|
|
13
|
+
if params.is_a? Integer
|
|
14
|
+
find_equals(:number, params)
|
|
15
|
+
else
|
|
16
|
+
k,v = params.first
|
|
17
|
+
find_equals k, v
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def method_missing(meth, *args, &block)
|
|
22
|
+
m = meth.to_s.match(/^find_by_(.+)/)
|
|
23
|
+
if m
|
|
24
|
+
key = m[1].to_sym
|
|
25
|
+
if Strike.new.respond_to? key
|
|
26
|
+
instance_eval "def #{meth}(val); find_equals :#{key}, val; end"
|
|
27
|
+
send meth, args.first
|
|
28
|
+
else
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
protected
|
|
37
|
+
|
|
38
|
+
def find_equals(key, value)
|
|
39
|
+
key = key.to_sym
|
|
40
|
+
value = value.to_s unless value.nil?
|
|
41
|
+
result = all.select do |s|
|
|
42
|
+
test = s.send(key)
|
|
43
|
+
test = test.to_s unless test.nil?
|
|
44
|
+
value == test
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
result = result.first if key == :number and not result.nil?
|
|
48
|
+
return result
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module DroneApi
|
|
4
|
+
class Strike
|
|
5
|
+
attr_reader :id, :number, :country, :date, :town, :location, :deaths,
|
|
6
|
+
:deaths_min, :deaths_max, :civilians, :injuries, :children, :tweet_id,
|
|
7
|
+
:bureau_id, :bij_summary_short, :bij_link, :target, :lat, :lon,
|
|
8
|
+
:articles, :names
|
|
9
|
+
|
|
10
|
+
# Return array of Strike objects from json string
|
|
11
|
+
#
|
|
12
|
+
def self.parse(js)
|
|
13
|
+
data = JSON.parse(js)
|
|
14
|
+
strikes = []
|
|
15
|
+
|
|
16
|
+
data['strike'].each do |s|
|
|
17
|
+
strike = Strike.new s
|
|
18
|
+
strikes << strike
|
|
19
|
+
end unless data['strike'].nil? or data['strike'].empty?
|
|
20
|
+
|
|
21
|
+
return strikes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Initialize attributes
|
|
25
|
+
#
|
|
26
|
+
def initialize(data = nil)
|
|
27
|
+
unless data.nil?
|
|
28
|
+
data = JSON.parse(data) if data.is_a? String
|
|
29
|
+
|
|
30
|
+
@id = data['_id'] || ''
|
|
31
|
+
@number = data['number'].to_i || 0
|
|
32
|
+
@country = data['country'] || ''
|
|
33
|
+
@date = data['date'] || ''
|
|
34
|
+
@town = data['town'] || ''
|
|
35
|
+
@location = data['location'] || ''
|
|
36
|
+
@deaths = data['deaths'].to_i || 0
|
|
37
|
+
@deaths_min = data['deaths_min'].to_i || 0
|
|
38
|
+
@deaths_max = data['deaths_max'].to_i || 0
|
|
39
|
+
@civilians = data['civilians'].to_i || 0
|
|
40
|
+
@injuries = data['injuries'].to_i || 0
|
|
41
|
+
@children = data['children'].to_i || 0
|
|
42
|
+
@tweet_id = data['tweet_id'] || ''
|
|
43
|
+
@bureau_id = data['bureau_id'] || ''
|
|
44
|
+
@summary_short = data['bij_summary_short'] || ''
|
|
45
|
+
@link = data['bij_link'] || ''
|
|
46
|
+
@target = data['target'] || ''
|
|
47
|
+
@lat = data['lat'] || ''
|
|
48
|
+
@lon = data['lon'] || ''
|
|
49
|
+
@articles = data['articles'] || ''
|
|
50
|
+
@names = data['names'] || ''
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/drone_api.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'drone_api/client'
|
|
2
|
+
require 'drone_api/request'
|
|
3
|
+
require 'drone_api/strike'
|
|
4
|
+
require 'drone_api/version'
|
|
5
|
+
|
|
6
|
+
module DroneApi
|
|
7
|
+
|
|
8
|
+
# Returns a new client
|
|
9
|
+
#
|
|
10
|
+
def self.new
|
|
11
|
+
Client.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Return the drone_api gem version
|
|
15
|
+
#
|
|
16
|
+
def self.version
|
|
17
|
+
"DroneApi version #{DroneApi::VERSION}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'DroneApi' do
|
|
4
|
+
it 'should return correct version string' do
|
|
5
|
+
DroneApi.version.should == "DroneApi version #{DroneApi::VERSION}"
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe 'DroneApi::Strike' do
|
|
10
|
+
before do
|
|
11
|
+
@strike = DroneApi::Strike.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
subject { @strike }
|
|
15
|
+
|
|
16
|
+
it { should_not respond_to(:some_random_thing) }
|
|
17
|
+
|
|
18
|
+
it { should respond_to(:id) }
|
|
19
|
+
it { should respond_to(:number) }
|
|
20
|
+
it { should respond_to(:country) }
|
|
21
|
+
it { should respond_to(:date) }
|
|
22
|
+
it { should respond_to(:town) }
|
|
23
|
+
it { should respond_to(:location) }
|
|
24
|
+
it { should respond_to(:deaths) }
|
|
25
|
+
it { should respond_to(:deaths_min) }
|
|
26
|
+
it { should respond_to(:deaths_max) }
|
|
27
|
+
it { should respond_to(:civilians) }
|
|
28
|
+
it { should respond_to(:injuries) }
|
|
29
|
+
it { should respond_to(:children) }
|
|
30
|
+
it { should respond_to(:tweet_id) }
|
|
31
|
+
it { should respond_to(:bureau_id) }
|
|
32
|
+
it { should respond_to(:bij_summary_short) }
|
|
33
|
+
it { should respond_to(:bij_link) }
|
|
34
|
+
it { should respond_to(:target) }
|
|
35
|
+
it { should respond_to(:lat) }
|
|
36
|
+
it { should respond_to(:lon) }
|
|
37
|
+
it { should respond_to(:articles) }
|
|
38
|
+
it { should respond_to(:names) }
|
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: drone_api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Bryan Fordham
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-06-28 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '2.13'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '2.13'
|
|
30
|
+
description: Library to access the DroneApi API
|
|
31
|
+
email:
|
|
32
|
+
- bfordham@gmail.com
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- .gitignore
|
|
38
|
+
- Gemfile
|
|
39
|
+
- LICENSE
|
|
40
|
+
- README.md
|
|
41
|
+
- Rakefile
|
|
42
|
+
- drone_api.gemspec
|
|
43
|
+
- lib/drone_api.rb
|
|
44
|
+
- lib/drone_api/client.rb
|
|
45
|
+
- lib/drone_api/request.rb
|
|
46
|
+
- lib/drone_api/strike.rb
|
|
47
|
+
- lib/drone_api/version.rb
|
|
48
|
+
- spec/drone_api_spec.rb
|
|
49
|
+
- spec/spec_helper.rb
|
|
50
|
+
homepage: https://github.com/bfordham/drone_api
|
|
51
|
+
licenses: []
|
|
52
|
+
post_install_message:
|
|
53
|
+
rdoc_options: []
|
|
54
|
+
require_paths:
|
|
55
|
+
- lib
|
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
+
none: false
|
|
64
|
+
requirements:
|
|
65
|
+
- - ! '>='
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
requirements: []
|
|
69
|
+
rubyforge_project:
|
|
70
|
+
rubygems_version: 1.8.23
|
|
71
|
+
signing_key:
|
|
72
|
+
specification_version: 3
|
|
73
|
+
summary: Allows retrieving drone strike info, and basic searching.
|
|
74
|
+
test_files:
|
|
75
|
+
- spec/drone_api_spec.rb
|
|
76
|
+
- spec/spec_helper.rb
|