Path pattern matching / - restkit

I'm trying to build a response descriptor for calls to the Dropbox metadata API.
Using the DBMetadata class from the Dropbox OS X SDK, here is my mapping:
RKObjectMapping *metadataMapping;
metadataMapping = [RKObjectMapping mappingForClass:[DBMetadata class]];
[metadataMapping addAttributeMappingsFromDictionary:#{#"thumb_exists": #"thumbnailExists",
#"bytes" : #"totalBytes",
#"modified" : #"lastModifiedDate",
#"client_mtime": #"clientMtime",
#"path" : #"path",
#"is_dir" : #"isDirectory",
#"hash" : #"hash",
#"size" : #"humanReadableSize",
#"root" : #"root",
#"icon" : #"icon",
#"rev" : #"rev",
#"revision" : #"revision",
#"is_deleted" : #"isDeleted"}];
[metadataMapping addRelationshipMappingWithSourceKeyPath:#"contents"
mapping:metadataMapping];
Here is my Response Descriptor (As much as I'd like to, I can't use :root:path, see NOTE 1):
RKResponseDescriptor *metadataResponse;
metadataResponse = [RKResponseDescriptor responseDescriptorWithMapping:metadataMapping
method:RKRequestMethodGET
pathPattern:#"metadata/dropbox:path"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self.manager addResponseDescriptor:metadataResponse];
The manager is setup as:
NSURL *baseAPIURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#://%#/%#/", kDBProtocolHTTPS, kDBDropboxAPIHost, kDBDropboxAPIVersion]];
self.manager = [RKObjectManager managerWithBaseURL:baseAPIURL];
self.manager.requestSerializationMIMEType = RKMIMETypeJSON;
The problem is that the #"metadata/dropbox:path" path pattern always fails:
DBMetadata *root;
root = [[DBMetadata alloc] initWithDictionary:#{#"root": #"dropbox",
#"path": #"/"}];
[self.manager getObject:root
path:#"metadata/dropbox/"
parameters:#{#"list": #"false"}
success:...
failure:...];
Result:
E restkit.network:RKObjectRequestOperation.m:213 GET
'https://api.dropbox.com/1/metadata/dropbox/?list=false' (200 OK / 0
objects) [request=0.0957s mapping=0.0000s total=0.0968s]: Error
Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response
descriptors match the response loaded." UserInfo=0x6000000ee900
{NSLocalizedFailureReason=A 200 response was loaded from the URL
'https://api.dropbox.com/1/metadata/dropbox/?list=false', which failed
to match all (0) response descriptors:,
NSErrorFailingURLStringKey=https://api.dropbox.com/1/metadata/dropbox/?list=false,
NSErrorFailingURLKey=https://api.dropbox.com/1/metadata/dropbox/?list=false,
NSUnderlyingError=0x6000000569b0 "No mappable object representations
were found at the key paths searched.", keyPath=null,
NSLocalizedDescription=No response descriptors match the response
loaded.}
But if I set the path pattern in the response descriptor to a static string (#"metadata/dropbox/"), it works:
I restkit.network:RKObjectRequestOperation.m:220 GET
'https://api.dropbox.com/1/metadata/dropbox/?list=false' (200 OK / 1
objects) [request=0.1027s mapping=0.0014s total=0.1034s]
Is it not possible to pass "/" as a path pattern parameter?
I also noticed that the error says that the response failed to match all (0) response descriptors. Shouldn't it be (1) in this case?

Related

How to access JSON from external data source in Terraform?

I am receiving JSON from a http terraform data source
data "http" "example" {
url = "${var.cloudwatch_endpoint}/api/v0/components"
# Optional request headers
request_headers {
"Accept" = "application/json"
"X-Api-Key" = "${var.api_key}"
}
}
It outputs the following.
http = [{"componentID":"k8QEbeuHdDnU","name":"Jenkins","description":"","status":"Partial Outage","order":1553796836},{"componentID":"ui","name":"ui","description":"","status":"Operational","order":1554483781},{"componentID":"auth","name":"auth","description":"","status":"Operational","order":1554483781},{"componentID":"elig","name":"elig","description":"","status":"Operational","order":1554483781},{"componentID":"kong","name":"kong","description":"","status":"Operational","order":1554483781}]
which is a string in terraform. In order to convert this string into JSON I pass it to an external data source which is a simple ruby function. Here is the terraform to pass it.
data "external" "component_ids" {
program = ["ruby", "./fetchComponent.rb",]
query = {
data = "${data.http.example.body}"
}
}
Here is the ruby function
#!/usr/bin/env ruby
require 'json'
data = JSON.parse(STDIN.read)
results = data.to_json
STDOUT.write results
All of this works. The external data outputs the following (It appears the same as the http output) but according to terraform docs this should be a map
external1 = {
data = [{"componentID":"k8QEbeuHdDnU","name":"Jenkins","description":"","status":"Partial Outage","order":1553796836},{"componentID":"ui","name":"ui","description":"","status":"Operational","order":1554483781},{"componentID":"auth","name":"auth","description":"","status":"Operational","order":1554483781},{"componentID":"elig","name":"elig","description":"","status":"Operational","order":1554483781},{"componentID":"kong","name":"kong","description":"","status":"Operational","order":1554483781}]
}
I was expecting that I could now access data inside of the external data source. I am unable.
Ultimately what I want to do is create a list of the componentID variables which are located within the external data source.
Some things I have tried
* output.external: key "0" does not exist in map data.external.component_ids.result in:
${data.external.component_ids.result[0]}
* output.external: At column 3, line 1: element: argument 1 should be type list, got type string in:
${element(data.external.component_ids.result["componentID"],0)}
* output.external: key "componentID" does not exist in map data.external.component_ids.result in:
${data.external.component_ids.result["componentID"]}
ternal: lookup: lookup failed to find 'componentID' in:
${lookup(data.external.component_ids.*.result[0], "componentID")}
I appreciate the help.
can't test with the variable cloudwatch_endpoint, so I have to think about the solution.
Terraform can't decode json directly before 0.11.x. But there is a workaround to work on nested lists.
Your ruby need be adjusted to make output as variable http below, then you should be fine to get what you need.
$ cat main.tf
variable "http" {
type = "list"
default = [{componentID = "k8QEbeuHdDnU", name = "Jenkins"}]
}
output "http" {
value = "${lookup(var.http[0], "componentID")}"
}
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
http = k8QEbeuHdDnU

Different request on same action with parameters

I want to search (say) "accounts" based on "name" or "status".
So I would like to have two actions :
GET /persons/?q=name==Jea*
GET /persons/?q=status==locked
How can I document that ?
I tried an Action with multiples transactions :
### GET /accounts{?q}
+ Request by name
+Parameters
+q (required, FIQLQuery)
**Only name is supported**
+ Request by status
+Parameters
+q (required, FIQLQuery)
**Only status is supported**
But Apiary editor complains because :
I must provide a message-body for my GET requests:
Message-body asset is expected to be a pre-formatted code block, every of its line indented by exactly 8 spaces or 2 tabs.
The + Parameters block is not recognized :
Ignoring unrecognized block
Thanks a lot
i can make solution that works for me.
Try this API Blueprint:
FORMAT: 1A
# requestByname
## Accounts [/accounts/?{q,type}]
### GET
+ Parameters
+ q (required, FIQLQuery)
+ type (string, `name` or `status`)
+ Request Name (application/json)
+ Response 200
{"name": "test"}
+ Request Status (application/json)
+ Response 200
{"status": 200}

Restkit - Matching a Path with ? and =

I've set up a response descriptor like this:
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:exhibitMapping method:RKRequestMethodAny pathPattern:#"?json=exhibits/get_exhibits" keyPath:#"d.exhibits" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
And made the request like so:
[[RKObjectManager sharedManager] getObjectsAtPath:#"?json=exhibits/get_exhibits" parameters:nil success:
But I get this error:
2014-03-17 11:14:39.856 MuseumMap[6135:60b] E app:ExhibitTableViewController.m:49 Load failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No response descriptors match the response loaded." UserInfo=0x8fb69f0 {NSErrorFailingURLStringKey=http://exhibits.wpengine.com/?json=exhibits/get_exhibits, NSLocalizedFailureReason=A 200 response was loaded from the URL 'http://exhibits.wpengine.com/?json=exhibits/get_exhibits', which failed to match all (1) response descriptors:
<RKResponseDescriptor: 0x9480270 baseURL=http://exhibits.wpengine.com/ pathPattern=?json=exhibits/get_exhibits statusCodes=200-299> failed to match: response path '?json=exhibits/get_exhibits' did not match the path pattern '?json=exhibits/get_exhibits'., NSLocalizedDescription=No response descriptors match the response loaded., keyPath=null, NSErrorFailingURLKey=http://exhibits.wpengine.com/?json=exhibits/get_exhibits, NSUnderlyingError=0x8fb6990 "No mappable object representations were found at the key paths searched."}
My thought is that there is a problem matching because of either the ? or the = in the pathPattern but I've tried escaping those and it doesn't seem to make a difference. Anyone have any ideas why this wouldn't match? The error message being response path '?json=exhibits/get_exhibits' did not match the path pattern '?json=exhibits/get_exhibits'. seems a bit off.
The problem was with the way the URL was formed. I changed my site to use permalinks instead of the ?json query parameters and that seemed to work. The path matching eliminates the query parameters before it matches so those cannot be used to match in restkit.
http://wordpress.org/plugins/json-api/other_notes/#1.1.-Requests

How to test Grails webflow with input parameter?

I'm in the process of writing tests for webflows and I have a webflow (A) that calls another webflow (sub-webflow) (B) during its execution. If A calls B it always states a required parameter / input with the call. Testing A alone is not a problem but how can I test B on it's own? The input parameter is states as:
input {
station(required: true)
}
I tried starting with startFlow() but that gives me the following exception:
Failure: testCreateWizardSubSubFlow(com.lstelcom.spectraweb.data.EquipmentFlowTests)
org.springframework.webflow.engine.FlowInputMappingException:
Errors occurred during input mapping on startup of the 'createWizardSubSub' flow;
errors = [[RequiredError#51a9e7fc mapping = station -> station, code = 'required', error = true, errorCause = [null], originalValue = [null], mappedValue = [null]]]
at grails.test.WebFlowTestCase.startFlow(WebFlowTestCase.groovy:130)
at com.lstelcom.spectraweb.data.EquipmentFlowTests.testCreateWizardSubSubFlow(EquipmentFlowTests.groovy:38)
A method call of startFlow with an input parameter (e.g., startFlow(new Station()) ) does not exist in WebFlowTestCase as I get the error:
groovy.lang.MissingMethodException: No signature of method: com.lstelcom.spectraweb.data.EquipmentFlowTests.startFlow() is applicable for argument types: (com.lstelcom.spectraweb.data.stations.Station) values: []
Possible solutions: getFlow(), getFlow()
at com.lstelcom.spectraweb.data.EquipmentFlowTests.testCreateWizardSubSubFlow(EquipmentFlowTests.groovy:38)
So the question is how can I test a webflow with input parameter?

Failed to communicate with qtkitserver: Connection invalid

In Mountain Lion (Fresh installation and not upgrade from 10.6 or 10.7), Im facing the issue while m trying to create a QTMovie, with the following exception:
2012-08-17 15:34:49.434 DemoApp[15995:303] Failed to communicate with qtkitserver:
Connection invalid
2012-08-17 15:34:49.434 DemoApp [15995:303] Failed to initializeServer(), returned 5
2012-08-17 15:34:55.614 DemoApp [15995:303] Error - Error Domain=NSOSStatusErrorDomain Code=-2012
"The movie contains an invalid data reference." (invalidDataRef)
UserInfo=0x108ae9ca0 {NSLocalizedDescription=The movie contains an invalid data reference.}
My code is as follows:
NSError *error = nil;
movie = [QTMovie movieWithURL:mediaURL error:&error];
NSLog(#"Error - %#", error);
But the 'movie' object is nil. Can anyone help me on this.
Thanks in advance,

Resources