diff --git a/ConfigurationOfShortener/ConfigurationOfShortener.class.st b/ConfigurationOfShortener/ConfigurationOfShortener.class.st new file mode 100644 index 0000000..78a2115 --- /dev/null +++ b/ConfigurationOfShortener/ConfigurationOfShortener.class.st @@ -0,0 +1,76 @@ +Class { + #name : #ConfigurationOfShortener, + #superclass : #Object, + #instVars : [ + 'project' + ], + #classVars : [ + 'LastVersionLoad' + ], + #category : #ConfigurationOfShortener +} + +{ #category : #'development support' } +ConfigurationOfShortener class >> DevelopmentSupport [ + +"See the methods in the 'development support' category on the class-side of MetacelloBaseConfiguration. Decide what development support methods you would like to use and copy them the the class-side of your configuration." + +] + +{ #category : #private } +ConfigurationOfShortener class >> ensureMetacelloBaseConfiguration [ + Smalltalk + at: #'ConfigurationOf' + ifAbsent: [ + | repository version | + repository := MCHttpRepository + location: 'http://smalltalkhub.com/mc/dkh/metacello/main' + user: '' + password: ''. + repository + versionReaderForFileNamed: 'Metacello-Base-dkh.107' + do: [ :reader | + version := reader version. + version load. + version workingCopy repositoryGroup addRepository: repository ] ] +] + +{ #category : #'development support' } +ConfigurationOfShortener class >> validate [ + "Check the configuration for Errors, Critical Warnings, and Warnings (see class comment for MetacelloMCVersionValidator for more information). + Errors identify specification issues that will result in unexpected behaviour when you load the configuration. + Critical Warnings identify specification issues that may result in unexpected behavior when you load the configuration. + Warnings identify specification issues that are technically correct, but are worth take a look at." + + "self validate" + + + self ensureMetacello. + ^ ((Smalltalk at: #MetacelloToolBox) validateConfiguration: self debug: #() recurse: false) explore +] + +{ #category : #accessing } +ConfigurationOfShortener >> customProjectAttributes [ + "Edit to return a collection of any custom attributes e.g. for conditional loading: Array with: #'Condition1' with: #'Condition2. + For more information see: http://code.google.com/p/metacello/wiki/CustomProjectAttrributes " + + ^ #() +] + +{ #category : #accessing } +ConfigurationOfShortener >> project [ + ^ project + ifNil: [ + "Bootstrap Metacello if it is not already loaded" + self class ensureMetacello. + project := MetacelloMCProject new projectAttributes: self customProjectAttributes. "Create the Metacello project" + (Smalltalk at: #'MetacelloVersionConstructor') on: self project: project. "Construct the project" + project loadType: #'linear'. "change to #atomic if desired" + project ] +] + +{ #category : #'symbolic versions' } +ConfigurationOfShortener >> stable: spec [ + + spec for: #common version: '1' +] diff --git a/ConfigurationOfShortener/package.st b/ConfigurationOfShortener/package.st new file mode 100644 index 0000000..6aaf271 --- /dev/null +++ b/ConfigurationOfShortener/package.st @@ -0,0 +1 @@ +Package { #name : #ConfigurationOfShortener } diff --git a/Shortener/Shortener.class.st b/Shortener/Shortener.class.st new file mode 100644 index 0000000..be29bd6 --- /dev/null +++ b/Shortener/Shortener.class.st @@ -0,0 +1,28 @@ +" +Please comment me using the following template inspired by Class Responsibility Collaborator (CRC) design: + +For the Class part: State a one line summary. For example, ""I represent a paragraph of text"". +I represent a wrapper for the is.gd ethical shortener that doesn't track its users and is carbon neutral +(see https://is.gd/ethics.php for more details). + +I use the public API as described in https://is.gd/apishorteningreference.php#restrict. +" +Class { + #name : #Shortener, + #superclass : #Object, + #category : #Shortener +} + +{ #category : #'as yet unclassified' } +Shortener class >> enlarge: url [ + "Given a shortened url in is.gd (or v.gd), I return the original url." + + ^ (ZnEasy get: 'https://is.gd/forward.php?format=simple&shorturl=', url) contents +] + +{ #category : #'accessing structure variables' } +Shortener class >> shorten: url [ + "I return the shortened url string as returned by https//is.gd ." + + ^ (ZnEasy get: 'https://is.gd/create.php?format=simple&url=', url) contents +] diff --git a/Shortener/ShortenerTest.class.st b/Shortener/ShortenerTest.class.st new file mode 100644 index 0000000..e465524 --- /dev/null +++ b/Shortener/ShortenerTest.class.st @@ -0,0 +1,29 @@ +" +A ShortenerTest is a test class for testing the behavior of Shortener +" +Class { + #name : #ShortenerTest, + #superclass : #TestCase, + #category : #'Shortener-Tests' +} + +{ #category : #tests } +ShortenerTest >> testEnlarging [ + "I thist that an already shortened address gives the proper result." + | shortenUrl | + shortenUrl := Shortener shorten: 'https://pharo.org'. + self assert: (Shortener enlarge: shortenUrl) equals: 'https://pharo.org' +] + +{ #category : #tests } +ShortenerTest >> testIsShortenerUp [ + self assert: ((ZnEasy get: 'https://is.gd') isSuccess) +] + +{ #category : #tests } +ShortenerTest >> testShortening [ + "I thist that an already shortened address gives the proper result." + | shortenUrl | + shortenUrl := Shortener shorten: 'https://pharo.org'. + self assert: (Shortener shorten: 'https://pharo.org') equals: shortenUrl +] diff --git a/Shortener/package.st b/Shortener/package.st new file mode 100644 index 0000000..4347175 --- /dev/null +++ b/Shortener/package.st @@ -0,0 +1 @@ +Package { #name : #Shortener }