gobble 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/console +14 -0
- data/bin/gobble +3 -0
- data/bin/setup +7 -0
- data/lib/gobble.rb +5 -0
- data/lib/gobble/tobi/constants.rb +8 -0
- data/lib/gobble/tobi/optprocess.rb +68 -0
- data/lib/gobble/tobi/parser.rb +59 -0
- data/lib/gobble/tobi/server.rb +31 -0
- data/lib/gobble/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3a7b24457c04b67cf5c34a0974bfabb707ffb133
|
4
|
+
data.tar.gz: 3ad1249167253f45bc5734b32973a834684fea33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c490a03c922803b35a6fc259cc243adde6ced928d7137151f160003d4e7004ca7dae89aa79913387f0f365662cfd8d655e1034a378aab54169b43a0579766eab
|
7
|
+
data.tar.gz: dfb7408a258834234040ba66a43c91bd232adf120ad4a74870e54637ed94a09bb8bf7a0324fa9b76527c57a7b478856af7abb4ae833fe4698fb3dc445cf4c85e
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gobble"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/gobble
ADDED
data/bin/setup
ADDED
data/lib/gobble.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "gobble/tobi/constants"
|
2
|
+
require "gobble/tobi/server"
|
3
|
+
|
4
|
+
module Gobble
|
5
|
+
module Tobi
|
6
|
+
class Process
|
7
|
+
include Gobble::Tobi::Constants
|
8
|
+
|
9
|
+
attr_accessor :options
|
10
|
+
attr_accessor :values
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@options = options
|
14
|
+
@values = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def process
|
18
|
+
save_key(options, values)
|
19
|
+
store_key(options, values)
|
20
|
+
store_url(options, values)
|
21
|
+
|
22
|
+
puts Gobble::Tobi::ServerGateway.new(values).communicate
|
23
|
+
end
|
24
|
+
|
25
|
+
def save_key(options, values)
|
26
|
+
if options[:save]
|
27
|
+
if options[:key]
|
28
|
+
File.open(FILE_NAME, "w+") { |file| file.write(options[:key]) }
|
29
|
+
else
|
30
|
+
puts "Save Error. Key argument required! "\
|
31
|
+
"Run gobble -h to view options"
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def store_key(options, values)
|
38
|
+
if options[:key]
|
39
|
+
values[:key] = options[:key]
|
40
|
+
else
|
41
|
+
if File.exist?(FILE_NAME)
|
42
|
+
values[:key] = File.open(FILE_NAME, "r") { |file|
|
43
|
+
file.read(options[:key])
|
44
|
+
}
|
45
|
+
else
|
46
|
+
puts "No key found! Key argument required. "\
|
47
|
+
"Run gobble -h to view options"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def store_url(options, values)
|
54
|
+
if options[:full_url]
|
55
|
+
values[:full_url] = options[:full_url]
|
56
|
+
else
|
57
|
+
puts "Full URL argument required. Run gobble -h to view options"
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
|
61
|
+
if options[:short_url]
|
62
|
+
values[:short_url] = options[:short_url]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "gobble/tobi/optprocess"
|
2
|
+
require "gobble/tobi/server"
|
3
|
+
require "gobble/tobi/constants"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
module Gobble
|
7
|
+
module Tobi
|
8
|
+
class Parser
|
9
|
+
def parse(args=ARGV)
|
10
|
+
options = {}
|
11
|
+
options[:save] = false
|
12
|
+
optparse = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: gobble -f [full_url] (-s [short_url]) -k "\
|
14
|
+
"[api_key] (--save)\n Options in round brackets are optional\n\n"
|
15
|
+
details_full = "-f full_url \t(full_url represents full_url to be "\
|
16
|
+
"shortened)\n"
|
17
|
+
details_short = "-s short_url \t(short_url represents custom short "\
|
18
|
+
"link. Optional. If not passed in, a unique one is generated)\n"
|
19
|
+
details_key = "-k api_key \t(api_key gotten from user account. Sign "\
|
20
|
+
"up on http://gobble-it.heroku.com for yours.)\n"
|
21
|
+
details_save = "--save \t\t(to save api key on this PC.)\n"
|
22
|
+
details_help = "-h \t\t(to show this message)\n"
|
23
|
+
|
24
|
+
opts.on('-f full_url') do |full_url|
|
25
|
+
options[:full_url] = full_url
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-k key') do |key|
|
29
|
+
options[:key] = key
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on('--save') do
|
33
|
+
options[:save] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on('-s short_url') do |short_url|
|
37
|
+
options[:short_url] = short_url
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on('-h') do
|
41
|
+
puts opts.banner << details_full << details_short <<
|
42
|
+
details_key << details_save << details_help
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
begin
|
49
|
+
optparse.parse!(args)
|
50
|
+
rescue
|
51
|
+
puts "Argument(s) not valid. Run gobble -h for instructions."
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
Process.new(options).process
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "gobble/tobi/constants"
|
3
|
+
|
4
|
+
module Gobble
|
5
|
+
module Tobi
|
6
|
+
class ServerGateway
|
7
|
+
include Gobble::Tobi::Constants
|
8
|
+
|
9
|
+
attr_accessor :values
|
10
|
+
|
11
|
+
def initialize(values)
|
12
|
+
@values = values
|
13
|
+
end
|
14
|
+
|
15
|
+
def communicate
|
16
|
+
actual_response = nil
|
17
|
+
uri = URI(FULL_URL + "/api/create")
|
18
|
+
uri.query = URI.encode_www_form(values)
|
19
|
+
|
20
|
+
res = Net::HTTP.get_response(uri)
|
21
|
+
|
22
|
+
if res.is_a?(Net::HTTPSuccess)
|
23
|
+
actual_response = res.body
|
24
|
+
end
|
25
|
+
|
26
|
+
actual_response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gobble
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobi Oduah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: For more details, Visit http://gobble-it.herokuapp.com/api for more instructions
|
56
|
+
email:
|
57
|
+
- tobi.oduah@andela.com
|
58
|
+
executables:
|
59
|
+
- gobble
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- bin/console
|
64
|
+
- bin/gobble
|
65
|
+
- bin/setup
|
66
|
+
- lib/gobble.rb
|
67
|
+
- lib/gobble/tobi/constants.rb
|
68
|
+
- lib/gobble/tobi/optprocess.rb
|
69
|
+
- lib/gobble/tobi/parser.rb
|
70
|
+
- lib/gobble/tobi/server.rb
|
71
|
+
- lib/gobble/version.rb
|
72
|
+
homepage: http://gobble-it.herokuapp.com
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
allowed_push_host: https://rubygems.org
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Easy-to-use gem to interface with the Gobble-It API
|
97
|
+
test_files: []
|