plexts 0.0.6

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b337f4b3a6f76429fb6a22ea9a78e55cdc23797a
4
+ data.tar.gz: c0a5968ffd838fd55abed0e980878649aef02c94
5
+ SHA512:
6
+ metadata.gz: 18582f1e0725968006c7d748c8c28ef32218e22b501c8a66d7469ff87192078b9c8b43ecb503b29ffa3c75ca24aa30176c20a2ecc43ecbddb3e7d1da8a2a960b
7
+ data.tar.gz: 7d177cf940d550db74ddaa5e87145186dc17bd8791cd3f84ccea180c22e9773768044576d00fd33354a923bf14d4bfcef32e5245e44d47aaa58bf8c365f3e0d1
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ intel.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake', '10.3.2'
4
+ gem 'rspec', '3.0.0'
5
+
6
+ # Specify your gem's dependencies in plexts.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,18 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+
15
+ Copyright © 2014 Takashi Funato <tfunato@gmail.com>
16
+ This work is free. You can redistribute it and/or modify it under the
17
+ terms of the Do What The Fuck You Want To Public License, Version 2,
18
+ as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Plexts
2
+
3
+ Ingress Intel Map API Caller
4
+
5
+ ## Description
6
+
7
+ * all, faction, alerts message to console
8
+ * get the information of the portals in Json format
9
+ * get the information of the artifacts in Json format
10
+
11
+ ## Setup
12
+
13
+ ```
14
+ cp .env.sample .env
15
+ ```
16
+
17
+ write .env
18
+
19
+ ## Using CLI
20
+
21
+
22
+ ```
23
+ $ rake build
24
+ plexts 0.0.1 built to pkg/plexts-0.0.1.gem.
25
+ $ gem install pkg/plexts-0.0.1.gem
26
+ Successfully installed plexts-0.0.1
27
+ Parsing documentation for plexts-0.0.1
28
+ Done installing documentation for plexts after 0 seconds
29
+ 1 gem installed
30
+ $ rbenb rehash # If necessary
31
+ $ plexts -h
32
+ Usage: plexts [options]
33
+ -c, --console show all or faction, aleart messages
34
+ -e, --entity show portals infomation of JSON format
35
+ --lat VALUE portal Latitude
36
+ --lng VALUE portal Longitude
37
+ -z VALUE map zoom level 1-20
38
+ -a, --artifacts artifacts infomation of JSON format
39
+ ```
40
+
41
+ ## Caution
42
+
43
+ This application should be used at your own risk.
44
+ When you use it, there is a possibility that the account is stopped.
45
+
46
+ ## Licence
47
+
48
+ Released under the [WTFPL license](http://www.wtfpl.net/).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ Rake::Task[:release].clear
data/bin/plexts ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'plexts'
5
+ require 'optparse'
6
+
7
+ Version = Plexts::VERSION
8
+
9
+ def cmd_line
10
+ args = {}
11
+ opts = OptionParser.new do |parser|
12
+ parser.on('-c', '--console', 'show all or faction, aleart messages') {|v| args[:c] = v}
13
+ parser.on('-e', '--entity', 'show portals infomation of JSON format') {|v| args[:e] = v}
14
+ parser.on('--minlat VALUE', 'south west area latitude') {|v| args[:lat1] = v}
15
+ parser.on('--minlng VALUE', 'south west area longitude') {|v| args[:lng1] = v}
16
+ parser.on('--maxlat VALUE', 'north east area latitude') {|v| args[:lat2] = v}
17
+ parser.on('--maxlng VALUE', 'north east area longitude') {|v| args[:lng2] = v}
18
+ parser.on('-z VALUE', 'map zoom level 1-20') {|v| args[:z] = v}
19
+ parser.on('-a', '--artifacts', 'artifacts infomation of JSON format') {|v| args[:a] = v}
20
+ parser.parse!(ARGV)
21
+ end
22
+ if args.size() == 0
23
+ puts opts
24
+ exit
25
+ end
26
+ args
27
+ end
28
+
29
+ args = cmd_line
30
+
31
+
32
+ if args[:c]
33
+ Plexts.to_console(args[:lat1], args[:lng1], args[:lat2], args[:lng2])
34
+ elsif args[:e]
35
+ if args[:z]
36
+ Plexts.get_entities(args[:lat1].to_f, args[:lng1].to_f, args[:lat2].to_f, args[:lng2].to_f, args[:z])
37
+ else
38
+ Plexts.get_entities(args[:lat1].to_f, args[:lng1].to_f, args[:lat2].to_f, args[:lng2].to_f)
39
+ end
40
+ elsif args[:a]
41
+ Plexts.get_artifacts()
42
+ end
data/intel.yml.sample ADDED
@@ -0,0 +1,3 @@
1
+ csrftoken: your_csrf_token_ftom_intel
2
+ SACSID: sacsid_from_intel_cookies
3
+ v: current_intel_dashboard_version
data/lib/plexts.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'plexts/plexts'
2
+ require 'plexts/entities'
3
+ require 'plexts/artifacts'
4
+ require 'plexts/to_console'
5
+ require 'plexts/intel_data'
6
+ require 'plexts/version'
7
+
8
+ module Plexts
9
+ end
@@ -0,0 +1,6 @@
1
+ module Plexts
2
+
3
+ def self.get_artifacts
4
+ get_intel_data('https://www.ingress.com/r/artifacts')
5
+ end
6
+ end
@@ -0,0 +1,53 @@
1
+ module Plexts
2
+
3
+ ZOOM_TO_NUM_TILES_PER_EDGE = [1,1,1,40,40,80,80,320,1000,2000,2000,4000,8000,16000,16000,32000]
4
+
5
+ # minLatE6, minLngE6: south west point
6
+ # maxLatE6, maxLngE6: north east point
7
+ def self.get_entities(minLatE6, minLngE6, maxLatE6, maxLngE6, zoom=20)
8
+ if !(minLatE6.between?(-90, 90) && minLngE6.between?(-180, 180)) || !(maxLatE6.between?(-90, 90) && maxLngE6.between?(-180, 180))
9
+ raise StandardError, "irregular parameter"
10
+ end
11
+
12
+ tiles = get_mercator_tiles(minLatE6, minLngE6, maxLatE6, maxLngE6, zoom)
13
+ get_entities_from_tiles(tiles)
14
+ end
15
+
16
+ def self.get_entities_from_tiles(tiles)
17
+ body = {
18
+ "tileKeys" => tiles,
19
+ }
20
+ get_intel_data('https://www.ingress.com/r/getEntities', body)
21
+ end
22
+
23
+ # parameter sample
24
+ # 17_7994_3544_0_8_100
25
+ # 17: zoom level
26
+ # 7994: mercator tile lan param
27
+ # 3544: mercator tile lng param
28
+ # 0: min portal level(0-8)
29
+ # 8: max portal level(0-8)
30
+ # 100: max portal health (25, 50, 75, 100)
31
+ def self.get_mercator_tiles(minLatE6, minLngE6, maxLatE6, maxLngE6, zoom=17, pMinLevel=0, pMaxLevel=8, maxHealth=100)
32
+ z = ZOOM_TO_NUM_TILES_PER_EDGE[zoom] || 32000
33
+ lat1_tile = self.get_tile_for_lat(minLatE6, z)
34
+ lat2_tile = self.get_tile_for_lat(maxLatE6, z)
35
+ lng1_tile = self.get_tile_for_lng(minLngE6, z)
36
+ lng2_tile = self.get_tile_for_lng(maxLngE6, z)
37
+ tiles = []
38
+ for x in lng1_tile..lng2_tile
39
+ for y in lat2_tile..lat1_tile
40
+ tiles.push([zoom, x, y, pMinLevel, pMaxLevel, maxHealth].join('_'))
41
+ end
42
+ end
43
+ tiles
44
+ end
45
+
46
+ def self.get_tile_for_lat(lat, z)
47
+ ((1 - Math.log(Math.tan(lat * Math::PI / 180) + 1 / Math.cos(lat * Math::PI / 180)) / Math::PI) / 2 * z).to_i
48
+ end
49
+
50
+ def self.get_tile_for_lng(lng, z)
51
+ ((lng + 180) / 360 * z).to_i
52
+ end
53
+ end
@@ -0,0 +1,46 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'json'
4
+ require 'yaml'
5
+
6
+ module Plexts
7
+
8
+ def self.get_intel_data(url, body={})
9
+ intel = YAML::load(File.open(File.join(Dir.pwd, 'intel.yml')))
10
+
11
+ cookie = {
12
+ 'csrftoken' => intel['csrftoken'],
13
+ 'SACSID' => intel['SACSID']
14
+ }
15
+ headers = {
16
+ 'content-Type' => 'application/json; charset=UTF-8',
17
+ 'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
18
+ 'x-csrftoken' => intel['csrftoken'],
19
+ 'referer' => 'https://www.ingress.com/intel',
20
+ 'cookie' => cookie.map{|k,v|
21
+ "#{k}=#{v}"
22
+ }.join('; ')
23
+ }
24
+
25
+ uri = URI(url)
26
+ https = Net::HTTP.new(uri.host, uri.port)
27
+ https.use_ssl = true
28
+ req = Net::HTTP::Post.new(uri.path, headers)
29
+ body[:v] = intel["v"]
30
+ req.body = body.to_json
31
+ res = https.request(req)
32
+
33
+ case res
34
+ when Net::HTTPSuccess then
35
+ if res.body.include?('Welcome to Ingress')
36
+ json = {error: 'SACSID incorrect'}.to_json
37
+ else
38
+ json = res.body
39
+ end
40
+ when Net::HTTPServerException, Net::HTTPForbidden then
41
+ json = {error: 'csrftoken incorrect'}.to_json
42
+ end
43
+
44
+ JSON.parse(json)
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ module Plexts
2
+
3
+ def self.get_plexts(minLatE6, minLngE6, maxLatE6, maxLngE6, maxTimestampMs=-1, tab='all')
4
+ body = {
5
+ "minLatE6" => minLatE6.to_s.gsub(/\./, '').to_i,
6
+ "minLngE6" => minLngE6.to_s.gsub(/\./, '').to_i,
7
+ "maxLatE6" => maxLatE6.to_s.gsub(/\./, '').to_i,
8
+ "maxLngE6" => maxLngE6.to_s.gsub(/\./, '').to_i,
9
+ "minTimestampMs" => -1,
10
+ "maxTimestampMs" => maxTimestampMs,
11
+ "tab" => tab
12
+ }
13
+ get_intel_data('https://www.ingress.com/r/getPlexts', body)
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ module Plexts
2
+
3
+ def self.to_console(minLatE6, maxLatE6, minLngE6, maxLngE6, maxTimestampMs=-1, tab='all')
4
+
5
+ json = get_plexts(minLatE6, maxLatE6, minLngE6, maxLngE6, maxTimestampMs, tab)
6
+
7
+ if json.has_key?('error')
8
+ puts json['error']
9
+ else
10
+ json["result"].reverse!.each do |plext|
11
+ s = plext[1].to_s
12
+ s = s[0, s.length - 3]
13
+
14
+ print Time.at(s.to_i).strftime("%Y-%m-%d %R | ")
15
+ text = ""
16
+ plext[2]["plext"]["markup"].each do |markups|
17
+ if markups[0] == "PLAYER"
18
+ if markups[1]["team"] == "RESISTANCE"
19
+ text << TermColor.blue
20
+ elsif markups[1]["team"] == "ENLIGHTENED"
21
+ text << TermColor.green
22
+ end
23
+ text << markups[1]["plain"]
24
+ text << TermColor.reset
25
+ elsif markups[0] == "PORTAL"
26
+ if markups[1]["team"] == "RESISTANCE"
27
+ text << TermColor.blue
28
+ else
29
+ text << TermColor.green
30
+ end
31
+ text << markups[1]["name"]
32
+ text << TermColor.reset
33
+ lat = markups[1]["latE6"] / 1e6
34
+ lag = markups[1]["lngE6"] / 1e6
35
+ text << " https://www.ingress.com/intel?ll=" + lat.to_s + "," + lag.to_s + "&z=19&pll=" + lat.to_s + "," + lag.to_s
36
+ elsif markups[0] == "TEXT"
37
+ if plext[2]["plext"]["categories"] == 4
38
+ text << TermColor.red
39
+ text << markups[1]["plain"]
40
+ text << TermColor.reset
41
+ else
42
+ text << markups[1]["plain"]
43
+ end
44
+ elsif markups[0] == "SECURE"
45
+ text << markups[1]["plain"]
46
+ elsif markups[0] == "SENDER"
47
+ text << TermColor.blue
48
+ text << markups[1]["plain"]
49
+ text << TermColor.reset
50
+ end
51
+ end
52
+ puts text
53
+ end
54
+ end
55
+ end
56
+
57
+ class TermColor
58
+ class << self
59
+ def reset ; c 0 ; end
60
+
61
+ def red ; c 31; end
62
+ def green ; c 32; end
63
+ def yellow ; c 33; end
64
+ def blue ; c 34; end
65
+ def magenta ; c 35; end
66
+ def cyan ; c 36; end
67
+ def white ; c 37; end
68
+
69
+ def c(num)
70
+ "\e[#{num.to_s}m"
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Plexts
2
+ VERSION = "0.0.6"
3
+ end
data/plexts.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'plexts/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "plexts"
8
+ spec.version = Plexts::VERSION
9
+ spec.authors = ["tfunato", "ailinykh"]
10
+ spec.email = ["tfunato@gmail.com"]
11
+ spec.summary = %q{Ingress COMM API caller.}
12
+ spec.description = %q{Ingress COMM API caller.}
13
+ spec.homepage = "https://github.com/ailinykh/plexts"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['plexts']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Plexts do
4
+ # TODO add test
5
+ #Plexts.get_entities(35.577807, 139.629278)
6
+ #Plexts.to_console
7
+ #Plexts.get_plexts
8
+ #Plexts.get_artifacts()
9
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'plexts'
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plexts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - tfunato
8
+ - ailinykh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-07-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Ingress COMM API caller.
57
+ email:
58
+ - tfunato@gmail.com
59
+ executables:
60
+ - plexts
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/plexts
72
+ - intel.yml.sample
73
+ - lib/plexts.rb
74
+ - lib/plexts/artifacts.rb
75
+ - lib/plexts/entities.rb
76
+ - lib/plexts/intel_data.rb
77
+ - lib/plexts/plexts.rb
78
+ - lib/plexts/to_console.rb
79
+ - lib/plexts/version.rb
80
+ - plexts.gemspec
81
+ - spec/plexts_spec.rb
82
+ - spec/spec_helper.rb
83
+ homepage: https://github.com/ailinykh/plexts
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.5
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Ingress COMM API caller.
107
+ test_files:
108
+ - spec/plexts_spec.rb
109
+ - spec/spec_helper.rb