goiu_shorten 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,48 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ # Compiled source #
7
+ ###################
8
+ *.com
9
+ *.class
10
+ *.dll
11
+ *.exe
12
+ *.o
13
+ *.so
14
+
15
+ # Packages #
16
+ ############
17
+ # it's better to unpack these files and commit the raw source
18
+ # git has its own built in compression methods
19
+ *.7z
20
+ *.dmg
21
+ *.gz
22
+ *.iso
23
+ *.jar
24
+ *.rar
25
+ *.tar
26
+ *.zip
27
+
28
+ # Logs and databases #
29
+ ######################
30
+ *.log
31
+ *.sql
32
+ *.sqlite
33
+
34
+ # OS generated files #
35
+ ######################
36
+ .DS_Store?
37
+ ehthumbs.db
38
+ Icon?
39
+ Thumbs.db
40
+
41
+ # IDE generated files #
42
+ #######################
43
+ *.esproj
44
+ *.idea
45
+
46
+ # Project-specific files #
47
+ ##########################
48
+ config.yaml
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p125@goiu_shorten"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in goiu_shorten.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # GoIU Shorten
2
+
3
+ ## Installation
4
+
5
+ gem install goiu_shorten
6
+
7
+ ## Usage
8
+
9
+ require 'goiu_shorten'
10
+
11
+ # Expand a short URL
12
+ GoiuShorten.expand 'short_url_here'
13
+
14
+ # Shorten a long URL
15
+ GoiuShorten.shorten 'long_url_here, passcode'
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "goiu_shorten/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "goiu_shorten"
7
+ s.version = GoiuShorten::VERSION
8
+ s.authors = ["David Poindexter"]
9
+ s.email = ["drpoindexter@gmail.com"]
10
+ s.homepage = "https://github.com/mtheoryx/goiu_shorten"
11
+ s.summary = %q{API interface to IU GoIU URL shortening service.}
12
+ s.description = %q{Provides easy interaction with the IU GoIU URL shortening service.}
13
+
14
+ s.rubyforge_project = "goiu_shorten"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'rspec'
24
+
25
+ s.add_runtime_dependency 'savon'
26
+ end
@@ -0,0 +1,12 @@
1
+ require "goiu_shorten/version"
2
+ require "goiu_shorten/goiu_shorten_api"
3
+
4
+ module GoiuShorten
5
+ def self.expand(short_url)
6
+ GoiuShortenApi.new.expand(short_url)
7
+ end
8
+
9
+ def self.shorten(long_url, passcode)
10
+ GoiuShortenApi.new.shorten(long_url, passcode)
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ require 'savon'
2
+
3
+ # Disable Savon logging
4
+ Savon.configure do |config|
5
+ config.log = false
6
+ end
7
+ # Disable HTTPI logging
8
+ HTTPI.log = false
9
+
10
+ module GoiuShorten
11
+ class GoiuShortenApi
12
+ def initialize
13
+ @client = Savon::Client.new do
14
+ wsdl.document = 'https://go.iu.edu/GoIUWebService.asmx?WSDL'
15
+ end
16
+ end
17
+
18
+ def expand(*short_url)
19
+ if short_url.nil? then raise ArgumentError end
20
+ api_response = @client.request :decode do
21
+ soap.body = {'tinyURL' => short_url}
22
+ end
23
+ result = api_response.to_hash[:decode_response][:decode_result]
24
+ result
25
+ end
26
+
27
+ def shorten(long_url, passcode)
28
+ unless (long_url =~ /^[a-z]{2,5}:\/\//)
29
+ raise ArgumentError
30
+ exit
31
+ end
32
+ unless passcode =~ /^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/
33
+ raise ArgumentError, "You must supply a passcode to shorten URLs."
34
+ exit
35
+ end
36
+ api_response = @client.request :encode do
37
+ soap.body = {'passCode' => passcode, 'longURL' => long_url}
38
+ end
39
+ result = api_response.to_hash[:encode_response][:encode_result]
40
+ # This tests for an error response about a bad, expired, invalid passcode
41
+ if (result =~ /^\*\*ERR\*\*\sPasscode/)
42
+ raise ArgumentError, "Not a valid passcode."
43
+ end
44
+ result
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module GoiuShorten
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe "GoiuShorten expand" do
5
+
6
+ before(:all) do
7
+ @sample_correct_long_url = "http://www.indiana.edu/~podcast/search/"
8
+ @sample_correct_short_url = "http://go.iu.edu/4Gb"
9
+ @sample_wrong_long_url = "http://davidrpoindexter.com/"
10
+ @sample_wrong_short_url = "http://go.iu.edu/i5"
11
+ end
12
+
13
+ it "should return a valid response when given a valid short url" do
14
+ GoiuShorten.expand(@sample_correct_short_url).should_not be_nil
15
+ end
16
+
17
+ it "should return the correct url for a given short url" do
18
+ long_url = GoiuShorten.expand(@sample_correct_short_url)
19
+ long_url.should == @sample_correct_long_url
20
+ end
21
+
22
+ it "should return an error if you don't supply a short url" do
23
+ GoiuShorten.expand(nil).should raise_exception
24
+ end
25
+
26
+ it "should return an error if you supply something other than a valid url" do
27
+ GoiuShorten.expand('simplestringhere').should raise_exception
28
+ end
29
+
30
+ it "should return an error if the given short url is not found" do
31
+ GoiuShorten.expand(@sample_wrong_short_url).should raise_exception
32
+ end
33
+
34
+ it "should return an error if the given short url is not valid" do
35
+ GoiuShorten.expand('http://go.iu.edu/').should raise_exception
36
+ end
37
+ end
38
+
39
+ describe "GoiuShorten shorten feature" do
40
+
41
+ before(:all) do
42
+ @sample_correct_long_url = "http://www.indiana.edu/~podcast/search/"
43
+ @sample_correct_short_url = "http://go.iu.edu/4Gb"
44
+ @sample_wrong_long_url = "http://davidrpoindexter.com/"
45
+ @sample_wrong_short_url = "http://go.iu.edu/i5"
46
+ @sample_wrong_passcode = "11111111-1111-1111-1111-111111111111"
47
+ config = YAML.load_file("config.yaml")
48
+ @sample_correct_passcode = config["config"]["passcode"]
49
+ end
50
+
51
+ it "should raise an error if you don't give it any arguments" do
52
+ expect {
53
+ GoiuShorten.shorten()
54
+ }.to raise_error(ArgumentError)
55
+ end
56
+
57
+ it "should raise an error if you mix up the order of your arguments" do
58
+ expect {
59
+ GoiuShorten.shorten(@sample_wrong_passcode, @sample_correct_long_url)
60
+ }.to raise_error(ArgumentError)
61
+ end
62
+
63
+ it "should raise a descriptive error if you don't supply a correctly formatted passcode" do
64
+ expect {
65
+ GoiuShorten.shorten(@sample_correct_long_url, 'wrongformatpasscode')
66
+ }.to raise_error(ArgumentError, "You must supply a passcode to shorten URLs.")
67
+ end
68
+
69
+ it "should raise an error for invalid passcode" do
70
+ expect {
71
+ GoiuShorten.shorten(@sample_correct_long_url, @sample_wrong_passcode)
72
+ }.to raise_error(ArgumentError, "Not a valid passcode.")
73
+ end
74
+
75
+ it "should return a short url when given a long url to shorten" do
76
+ GoiuShorten.shorten(@sample_correct_long_url, @sample_correct_passcode).should =~ /^http:\/\/go.iu.edu\//
77
+ end
78
+
79
+ it "should return a short url when given a long url" do
80
+ GoiuShorten.shorten(@sample_correct_long_url, @sample_correct_passcode).should == @sample_correct_short_url
81
+ end
82
+ end
@@ -0,0 +1,7 @@
1
+ require 'goiu_shorten'
2
+
3
+ RSpec.configure do |config|
4
+ config.color_enabled = true
5
+ config.tty = true
6
+ config.formatter = :documentation
7
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goiu_shorten
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Poindexter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70260313569380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70260313569380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70260313568920 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70260313568920
36
+ - !ruby/object:Gem::Dependency
37
+ name: savon
38
+ requirement: &70260313568420 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70260313568420
47
+ description: Provides easy interaction with the IU GoIU URL shortening service.
48
+ email:
49
+ - drpoindexter@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rvmrc
56
+ - Gemfile
57
+ - README.md
58
+ - Rakefile
59
+ - goiu_shorten.gemspec
60
+ - lib/goiu_shorten.rb
61
+ - lib/goiu_shorten/goiu_shorten_api.rb
62
+ - lib/goiu_shorten/version.rb
63
+ - spec/lib/goiu_shorten_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/mtheoryx/goiu_shorten
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project: goiu_shorten
85
+ rubygems_version: 1.8.17
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: API interface to IU GoIU URL shortening service.
89
+ test_files:
90
+ - spec/lib/goiu_shorten_spec.rb
91
+ - spec/spec_helper.rb