Skip to content

Commit

Permalink
メソッドのリファクタリングを実施。まだ実用できる段階ではない。
Browse files Browse the repository at this point in the history
  • Loading branch information
KazunoriUeda committed Oct 2, 2018
1 parent f40efde commit 581c192
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 52 deletions.
1 change: 1 addition & 0 deletions Google-API.package/GaGoogleApiBrowser.class/class/open.st
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
as yet unclassified
open
<script>
Smalltalk garbageCollect.
^ self new openAsMorph
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"class" : {
"open" : "RichardPrinz 5/12/2014 17:00" },
"open" : "KazunoriUeda 10/2/2018 16:18" },
"instance" : {
"apiList" : "RichardPrinz 4/4/2014 12:41",
"apiListIndex" : "RichardPrinz 4/4/2014 12:34",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
actions
createApi: apiDiscoveryObj inCategory: apiClassCategory
| apiDefUrl apiDef apiDefObj apiName apiClassName apiAuth proxy url rootUrl des ver doc src |

Expand Down Expand Up @@ -29,7 +29,7 @@ createApi: apiDiscoveryObj inCategory: apiClassCategory
doc ifNotNil: [ des := des, 'Documentation: ', doc, String cr ].

" create base class for this api "
apiClassName := 'Google', apiName capitalized, 'Api'.
apiClassName := self defaultClassNamePrefix, 'Google', apiName capitalized, 'Api'.
proxy := GaGoogleApiTools
createClassNamed: apiClassName
in: apiClassCategory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
actions
createClassesFromResource: anApiDef underParentClass: aClass withClassNamePrefix: aClassNamePrefix inCategory: aClassCategory comment: aComment

| res prefix |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
actions
createMethodFromMethodDef: methodDef inClass: aClass named: methodName
| sources |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
actions
createMethodsFromApiDef: apiDef inClass: aClass
| methods cnt |

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
actions
createSourceFromMethodDef: methodDef named: methodName
| selector selector2 comment methodComment paramComment source source2 pathVar actionVar
paramDef isFirstParam isOptional isUpload uploadDef maxUpload acceptedMimes uploadProt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
defaultClassNamePrefix: anObject
defaultClassNamePrefix := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
defaultClassNamePrefix
^ defaultClassNamePrefix ifNil: [ defaultClassNamePrefix := '' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class initialization
initialize
defaultClassNamePrefix := nil
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"class" : {
"createApi:inCategory:" : "KazunoriUeda 10/2/2018 15:58",
"createApi:inCategory:" : "KazunoriUeda 10/2/2018 16:28",
"createClassesFromResource:underParentClass:withClassNamePrefix:inCategory:comment:" : "KazunoriUeda 10/2/2018 15:58",
"createMethodFromMethodDef:inClass:named:" : "KazunoriUeda 10/2/2018 15:58",
"createMethodsFromApiDef:inClass:" : "RichardPrinz 5/12/2014 17:27",
"createSourceFromMethodDef:named:" : "KazunoriUeda 10/2/2018 09:47" },
"createSourceFromMethodDef:named:" : "KazunoriUeda 10/2/2018 09:47",
"defaultClassNamePrefix" : "KazunoriUeda 10/2/2018 16:24",
"defaultClassNamePrefix:" : "KazunoriUeda 10/2/2018 16:23",
"initialize" : "KazunoriUeda 10/2/2018 16:24" },
"instance" : {
} }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"category" : "Google-API",
"classinstvars" : [
],
"defaultClassNamePrefix" ],
"classvars" : [
],
"commentStamp" : "RichardPrinz 3/4/2015 17:21",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
authentication
authenticationCredentialsBaseDirectory
^ FileSystem workingDirectory.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
authentication
authenticationCredentialsFile
authenticationCredentialsFile ifNil: [ | dir fn |
dir := FileSystem workingDirectory.
dir := self authenticationCredentialsBaseDirectory.
fn := ( GaGoogleApiTools replaceInvalidPathChars: self apiName ), '.', self id, '.auth.json'.
fn := dir / 'google_api_data' / fn.
fn := dir asFileReference / 'google_api_data' / fn.
authenticationCredentialsFile := fn fullName ].

^ authenticationCredentialsFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
actions-http
get: apiUrl token: apiToken
| url req |
url := ( ZnUrl fromString: apiUrl )
queryAt: 'access_token' put: apiToken;
yourself.
req := ZnRequest get: url.
^req
32 changes: 7 additions & 25 deletions Google-API.package/GaGoogleApiProxy.class/instance/initialize.st
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
as yet unclassified
initialize-release
initialize
super initialize.

methodAction := Dictionary new.

methodAction at: #GET put: [ :apiUrl :token || url req |
url := ( ZnUrl fromString: apiUrl )
queryAt: 'access_token' put: token;
yourself.
req := ( ZnRequest get: url ).
req ].

methodAction at: #PUT put: [ :apiUrl :token || url req |
url := ( ZnUrl fromString: apiUrl )
queryAt: 'access_token' put: token;
yourself.
req := ( ZnRequest put: url ).
req ].

methodAction at: #POST put: [ :apiUrl :token || url req |
url := ( ZnUrl fromString: apiUrl )
queryAt: 'access_token' put: token;
yourself.
req := ( ZnRequest post: url ).
req ].

methodActions := {
#GET -> #get:token:.
#PUT -> #put:token:.
#POST -> #post:token:.
} asDictionary

Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
api
makeRequestTo: aUrl usingMethod: httpMethod with: aParamDictionary
| a req res client returnCode auth content |
| answerSelector req res client returnCode auth content a |

session ifNil: [
self error: 'Authenticate API first with #authenticate' ].

a := methodAction at: httpMethod ifAbsent: [
self error: 'Unsupported http method (', httpMethod, ')' ].
answerSelector := self methodActions at: httpMethod ifAbsent: [ self error: 'Unsupported http method (', httpMethod, ')' ].

client := ZnClient new.

" create request "
req := a value: aUrl value: ( session accessToken ).
req := self perform: answerSelector with: aUrl with: session accessToken.

client
request: req;
Expand All @@ -21,9 +20,10 @@ makeRequestTo: aUrl usingMethod: httpMethod with: aParamDictionary
req entity: GaMultiPartMixedEntity new.
client request url queryAt: 'uploadType' add: 'multipart'.

content := aParamDictionary at: 'CONTENT' ifAbsent: [ ].
aParamDictionary removeKey: 'CONTENT' ifAbsent: [ ].
content := ( Base64MimeConverter mimeEncode: content readStream ) contents.
aParamDictionary at: 'CONTENT' ifPresent: [ :cont |
aParamDictionary removeKey: 'CONTENT' ifAbsent: [ ].
content := ( Base64MimeConverter mimeEncode: cont readStream ) contents.
].
contentMime := aParamDictionary at: 'mimeType' ifAbsent: [ 'application/octet-stream' ].
json := NeoJSONWriter toString: aParamDictionary.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
methodActions
^methodActions
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
actions-http
post: apiUrl token: apiToken
| url req |
url := ( ZnUrl fromString: apiUrl )
queryAt: 'access_token' put: apiToken;
yourself.
req := ZnRequest post: url.
^req
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
actions-http
put: apiUrl token: apiToken
| url req |
url := ( ZnUrl fromString: apiUrl )
queryAt: 'access_token' put: apiToken;
yourself.
req := ZnRequest put: url.
^req
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
registration
registrationCredentialsFile
registrationCredentialsFile ifNil: [ | dir fn |
dir := FileSystem workingDirectory.
dir := self authenticationCredentialsBaseDirectory.
fn := ( GaGoogleApiTools replaceInvalidPathChars: self apiName ), '.', self id, '.config.json'.
fn := dir / 'google_api_data' / fn.
fn := dir asFileReference / 'google_api_data' / fn.
registrationCredentialsFile := fn fullName ].

^ registrationCredentialsFile
13 changes: 9 additions & 4 deletions Google-API.package/GaGoogleApiProxy.class/methodProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
"authenticate:" : "RichardPrinz 5/25/2014 20:11",
"authenticateRefresh" : "RichardPrinz 5/25/2014 20:22",
"authenticationCredentials" : "RichardPrinz 5/20/2014 20:05",
"authenticationCredentialsFile" : "KazunoriUeda 10/2/2018 15:58",
"authenticationCredentialsBaseDirectory" : "KazunoriUeda 10/2/2018 16:44",
"authenticationCredentialsFile" : "KazunoriUeda 10/2/2018 16:55",
"authenticationCredentialsFile:" : "RichardPrinz 5/14/2014 17:53",
"basePath" : "RichardPrinz 5/9/2014 15:30",
"get:token:" : "KazunoriUeda 10/2/2018 17:40",
"id" : "RichardPrinz 5/22/2014 16:36",
"id:" : "KazunoriUeda 10/2/2018 15:58",
"initialize" : "RichardPrinz 5/28/2014 19:23",
"makeRequestTo:usingMethod:with:" : "KazunoriUeda 10/2/2018 15:57",
"initialize" : "KazunoriUeda 10/2/2018 17:44",
"makeRequestTo:usingMethod:with:" : "KazunoriUeda 10/2/2018 17:48",
"methodActions" : "KazunoriUeda 10/2/2018 17:45",
"post:token:" : "KazunoriUeda 10/2/2018 17:42",
"put:token:" : "KazunoriUeda 10/2/2018 17:42",
"register" : "RichardPrinz 5/20/2014 20:07",
"register:" : "RichardPrinz 5/25/2014 20:12",
"registrationCredentials" : "RichardPrinz 5/20/2014 20:06",
"registrationCredentialsFile" : "KazunoriUeda 10/2/2018 15:58",
"registrationCredentialsFile" : "KazunoriUeda 10/2/2018 16:54",
"registrationCredentialsFile:" : "RichardPrinz 5/14/2014 17:51",
"replacePlaceholdersIn:with:" : "RichardPrinz 4/3/2014 17:48",
"scopes" : "RichardPrinz 5/13/2014 17:19",
Expand Down
2 changes: 1 addition & 1 deletion Google-API.package/GaGoogleApiProxy.class/properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"session",
"registrationCredentialsFile",
"authenticationCredentialsFile",
"methodAction" ],
"methodActions" ],
"name" : "GaGoogleApiProxy",
"pools" : [
],
Expand Down
2 changes: 1 addition & 1 deletion Google-API.package/monticello.meta/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(name 'Google-API-KazunoriUeda.7' message 'empty log message' id 'dd697465-f631-4d3b-860e-83805e65a0bf' date '2 October 2018' time '4:01:32.079082 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.6' message 'empty log message' id '744a24ed-9cb6-4066-a720-750068fea7bc' date '2 October 2018' time '4:00:24.360053 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.5' message 'empty log message' id '33aef2d1-9655-4449-b2c4-d1a49f31b8de' date '2 October 2018' time '3:59:43.561324 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.3' message 'empty log message' id '89416a47-4fd6-4315-a2b7-ea9332a3db08' date '2 October 2018' time '9:54:42.236345 am' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.2' message 'empty log message' id 'c72b61cb-4e4c-4655-b0a3-f9abac56cd04' date '2 October 2018' time '9:51:58.389512 am' author 'KazunoriUeda' ancestors ((name 'Google-API-RichardPrinz.1' message 'Initial commit' id 'a27b8d83-3b26-5048-9b29-cb603b12b5d3' date '19 March 2015' time '5:35:50.915345 pm' author 'RichardPrinz' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())
(name 'Google-API-KazunoriUeda.8' message 'empty log message' id 'b2a9f061-37e4-4ebf-814b-3c6abdaa4810' date '2 October 2018' time '5:50:21.872255 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.7' message 'empty log message' id 'dd697465-f631-4d3b-860e-83805e65a0bf' date '2 October 2018' time '4:01:32.079082 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.6' message 'empty log message' id '744a24ed-9cb6-4066-a720-750068fea7bc' date '2 October 2018' time '4:00:24.360053 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.5' message 'empty log message' id '33aef2d1-9655-4449-b2c4-d1a49f31b8de' date '2 October 2018' time '3:59:43.561324 pm' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.3' message 'empty log message' id '89416a47-4fd6-4315-a2b7-ea9332a3db08' date '2 October 2018' time '9:54:42.236345 am' author 'KazunoriUeda' ancestors ((name 'Google-API-KazunoriUeda.2' message 'empty log message' id 'c72b61cb-4e4c-4655-b0a3-f9abac56cd04' date '2 October 2018' time '9:51:58.389512 am' author 'KazunoriUeda' ancestors ((name 'Google-API-RichardPrinz.1' message 'Initial commit' id 'a27b8d83-3b26-5048-9b29-cb603b12b5d3' date '19 March 2015' time '5:35:50.915345 pm' author 'RichardPrinz' ancestors () stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())) stepChildren ())

0 comments on commit 581c192

Please sign in to comment.