geoloqi-simplegeo-import 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Geoloqi's SimpleGeo Import Tool - Transfer your data out of SimpleGeo and into Geoloqi with one command! ==
2
+ This tool will let you automatically transfer SimpleGeo data over to Geoloqi. It makes Geoloqi Layers for each Simplegeo Layer, and converts Records to Geoloqi Places for each of the layer!
3
+
4
+ All you need to run the command is a Geoloqi Access Token, and the SimpleGEO OAuth Key and Secret. You can sign up for a Geoloqi account at [https://geoloqi.com The Geoloqi Web Site] and retrieve your access token from the [https://developers.geoloqi.com Geoloqi Developers site].
5
+
6
+ This script is provided as an executable via rubygems, which means it runs on any Mac OSX computer out-of-the-box (and on any Windows/Linux machines with ruby available).
7
+
8
+ ## Installation
9
+ gem install geoloqi-simplegeo-import
10
+
11
+ ## Usage
12
+ $ geoloqi-simplegeo-import YOUR_GEOLOQI_ACCESS_TOKEN YOUR_SIMPLEGEO_OAUTH_KEY YOUR_SIMPLEGEO_OAUTH_SECRET
13
+
14
+ The script will output information on the transferred data, and give you a link to our Layer Editor so you can see and edit your Layers and Places (we have a GUI interface for your data!).
15
+
16
+ ## Bugs
17
+ Feel free to file any issues on Github, we will respond to them as soon as possible. If you need any features here we haven't provided, don't hesitate to contact us.
18
+
19
+ ## TODO
20
+ This is a quick-fix solution. However we are planning on making a more stable, complete tool for importing data to Geoloqi from other sources (and for exporting your data out of Geoloqi). We feel it's in your best interest to have total control of your data at all times, and we want to help you solve problems, not lock you into our platform.
21
+
22
+ ## Authors
23
+ [https://github.com/kyledrake Kyle Drake]
24
+ [https://github.com/aaronpk Aaron Parecki]
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'geoloqi'
4
+ require 'oauth'
5
+
6
+ if ARGV.length != 3
7
+ puts 'Usage: geoloqi-simplegeo-import GEOLOQI_ACCESS_TOKEN SIMPLEGEO_OAUTH_KEY SIMPLEGEO_OAUTH_SECRET'
8
+ exit
9
+ end
10
+
11
+ # TODO: Containerize in class
12
+ module Geoloqi
13
+ module SimpleGeo
14
+ SITE = 'http://api.simplegeo.com'
15
+ VERSION = '0.1'
16
+ class Session
17
+ def initialize(key, secret)
18
+ consumer = OAuth::Consumer.new key, secret, :site => SITE
19
+ @access_token = OAuth::AccessToken.new consumer
20
+ end
21
+
22
+ def get(path, args={}); run(:get, path, args) end
23
+ def put(path, args={}); run(:put, path, args) end
24
+ def delete(path, args={}); run(:delete, path, args) end
25
+
26
+ def run(meth, path, args)
27
+ if meth == :get
28
+ query = "#{SITE}/#{VERSION}/#{path}"
29
+ if args != {}
30
+ query += "?#{Rack::Utils.build_query args}"
31
+ end
32
+ result = @access_token.send meth, query
33
+ else
34
+ result = @access_token.send meth, "#{SITE}/#{VERSION}/#{path}", args.to_json, 'Content-Type'=>'application/json'
35
+ end
36
+ Response.new result.code, result.body
37
+ end
38
+ end
39
+
40
+ class Response
41
+ attr_reader :status, :body
42
+ alias_method :code, :status
43
+ def initialize(status, body)
44
+ @status = status
45
+ @body = JSON.parse body, :symbolize_names => true
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ geoloqi_access_token, simplegeo_oauth_key, simplegeo_oauth_secret = ARGV
52
+
53
+ simplegeo_session = Geoloqi::SimpleGeo::Session.new simplegeo_oauth_key, simplegeo_oauth_secret
54
+ geoloqi_session = Geoloqi::Session.new :access_token => geoloqi_access_token
55
+
56
+ layers_cursor = ''
57
+
58
+ while layers_cursor do
59
+ layers_result = simplegeo_session.get 'layers.json'
60
+ layers_result.body[:layers].each do |layer|
61
+
62
+ geoloqi_layer_name = layer[:title] || layer[:name]
63
+
64
+ puts "\n\n#############\nMigrating layer \"#{layer[:name]}\" with title \"#{layer[:title]}\".\n\n"
65
+
66
+ layer_result = geoloqi_session.post 'layer/create', {
67
+ :name => geoloqi_layer_name,
68
+ :key => layer[:name]
69
+ }
70
+
71
+ puts "This layer is named \"#{geoloqi_layer_name}\" on Geoloqi and has an ID of \"#{layer_result[:layer_id]}\"!\n\n"
72
+
73
+ records_cursor = ''
74
+
75
+ print "IMPORTING POINTS AS GEOLOQI PLACES (SimpleGeo ID => Geoloqi ID): "
76
+
77
+ while records_cursor do
78
+ records_result = simplegeo_session.get "records/#{layer[:name]}/nearby/0,0.json", {
79
+ :bbox => '-90,-180,90,180',
80
+ :limit => 10,
81
+ :cursor => records_cursor
82
+ }
83
+
84
+ records_result.body[:features].each do |feature|
85
+
86
+ geoloqi_place_name = (feature[:properties][:name] if feature[:properties] && feature[:properties][:name]) || nil
87
+ geoloqi_place_description = (feature[:properties][:description] if feature[:properties] && feature[:properties][:description]) || nil
88
+ result = geoloqi_session.post 'place/create', {
89
+ :name => geoloqi_place_name,
90
+ :description => geoloqi_place_description,
91
+ :latitude => feature[:geometry][:coordinates][1],
92
+ :longitude => feature[:geometry][:coordinates][0],
93
+ :layer_id => layer_result[:layer_id],
94
+ :key => "simplegeo-#{feature[:id]}",
95
+ :extra => feature[:properties]
96
+ }
97
+ print "#{feature[:id]} => #{result[:place_id]}, "
98
+ STDOUT.flush
99
+ end
100
+
101
+ records_cursor = records_result.body[:next_cursor]
102
+ end
103
+
104
+ puts "\n\nLayer \"#{layer[:name]}\" import complete! View and edit your layer on a map here: https://geoloqi.com/layers/#{layer_result[:layer_id]}/edit"
105
+ end
106
+
107
+
108
+ layers_cursor = layers_result.body[:next_cursor]
109
+ end
110
+
111
+ puts "\nDone importing! Thanks for using Geoloqi.\n"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "geoloqi-simplegeo-import"
6
+ s.version = '0.0.1'
7
+ s.authors = ["Kyle Drake"]
8
+ s.email = ["kyledrake@gmail.com"]
9
+ s.homepage = ""
10
+ s.summary = %q{Imports SimpleGeo Storage into Geoloqi}
11
+ s.description = %q{Imports SimpleGeo Storage into Geoloqi! Translates layers to layers, and "records" to places, maintaining the relationships and properties.}
12
+
13
+ s.rubyforge_project = "geoloqi-simplegeo-import"
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
+ s.executables = %w(geoloqi-simplegeo-import)
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_dependency 'geoloqi'
23
+ s.add_dependency 'oauth'
24
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geoloqi-simplegeo-import
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Kyle Drake
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-01-13 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: geoloqi
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: oauth
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ description: Imports SimpleGeo Storage into Geoloqi! Translates layers to layers, and "records" to places, maintaining the relationships and properties.
45
+ email:
46
+ - kyledrake@gmail.com
47
+ executables:
48
+ - geoloqi-simplegeo-import
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - bin/geoloqi-simplegeo-import
59
+ - geoloqi-simplegeo-import.gemspec
60
+ has_rdoc: true
61
+ homepage: ""
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: geoloqi-simplegeo-import
86
+ rubygems_version: 1.3.6
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Imports SimpleGeo Storage into Geoloqi
90
+ test_files: []
91
+