Instead of a clustered:
- (void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
if (objectLoader.method == RKRequestMethodGET) {
if ([objectLoader.resourcePath isEqualToString:#"/blah"]) {
// ...
}
} else if (objectLoader.method == RKRequestMethodPUT) {
if ([objectLoader.resourcePath hasSuffix:#"/blahblah"]) {
// ...
}
} else if (objectLoader.method == RKRequestMethodPOST) {
if ([objectLoader.resourcePath isEqualToString:#"/blahblahblah"]) {
// ...
}
}
}
I'd prefer a block approach, especially for simpler requests without any object mapping. Is there any documentation or example of how to use block response?
I don't think there is support for this configuration in the latest (0.10.1) version of RestKit.
There is - (void)loadObjectsAtResourcePath:(NSString *)resourcePath usingBlock:(RKObjectLoaderBlock)block selector, however the block is invoked to allow you to configure the ObjectLoader.
You may also use userData property to distinguish multiple requests, i provided more details in this answer.
With 0.10.1, you can use blocks for POST, GET etc calls, check out this SO answer
Related
I have a kotlin kotest (formerly known as kotlintest) BehaviorSpec
with one Given("...") and many When("...") Then("...") under it
I want to execute a cleanup after the whole Spec (respectively every Given clause) has finished.
#MicronautTest
class StructurePersistSpec(
private val iC : InstancesC
) : BehaviorSpec({
// afterSpec {
finalizeSpec {
cleanup()
}
Given("...") {
When("...") {
Then("...") {
...
}
Then("...") {
...
}
}
When("...") {
Then("...") {
...
}
Then("...") {
...
}
}
}
...
}
on using afterSpec { } I get multiple calls (amount of Whens??) to the afterSpec { } clause and NOT just one after the Spec finished (or finishing of the/each Given Clause)
on using finalizeSpec { } it does NOT get called at all (breakpoint inside it is never hit)
what am I doing wrong?
or did I miss some fancy characteristics of BehaviorSpecs ?
The reason you are getting multiple calls is that probably you have set a different IsolationMode for your test.
That would mean your Spec will be recreated (and then cleaned) for every test. In order to have a single afterSpec call from the framework, your IsolationMode must be set to SingleInstance.
Bare in mind that might affect the way your tests are being executed hence their validity or ability to pass.
Documentation: https://kotest.io/isolation_mode/
I am sending a value via MyRepository.myConflatedChannel.offer(myvalue).
I then expect to receive it in collect { } or onEach { } blocks in my ViewModel. However, neither function is invoked. It is as if nothing is passed down the ConflatedBroadcastChannel.
Has anybody seen a similar problem?
Make sure you properly work with receiving values.
If you use the ConflatedBroadcastChannel, you can use either OpenSubscription to get a ReceiveChannel or you can represent it as flow (with asFlow).
Note that consume and consumeEach are terminal, they perform an action and then cancel the channel after the execution of the block. See this.
First case:
val receivingChannel = MyRepository.myConflatedChannel.openSubscription()
// then you can consume values using for example a for loop, e.g.:
launch {
for (value in receivingChannel) {
// do something
}
}
Second case:
val receivingFlow = MyRepository.myConflatedChannel.asFlow()
launch {
receivingFlow.collect {
// do something
}
}
I am building an API using Ratpack and Groovy. The POST API is always giving:
405-Method not Found Error
This is a snippet from POST Endpoint Handler. In this code, promiseSingle, then, observe, map, doOnNext, doOnError, etc.
RxJAVA functions are not working. Is there any reason why RxJava methods are not working?
saveJsonAsData(context, id)
.promiseSingle()
.then { Data updateddata ->
context.response.headers
.add(HttpHeaderNames.LOCATION, "/api/save/${updateddata.id}/${updateddata.value}")
context.response.status(HttpResponseStatus.CREATED.code())
.send()
}
}
protected Observable<Data> saveJsonAsData(GroovyContext context, String id) {
context.request.body.observe()
.map { TypedData typedData -> extractData(context, typedData) }
.doOnNext { Data data ->
data.id = id
validatorWrapper.validate(data)
}
.flatMap(data.&save as Func1)
.doOnError { Throwable throwable -> log.error("Error saving data", throwable) }
}
The issue is not so much with Rx as it is with the usage of the Context.
You should try to keep the response handling logic within your Handler, that is don't pass the Context around, rather get the objects you need and pass them to your services.
As an example
path('myendpoint') { MyRxService service ->
byMethod {
get {
// do something when request is GET
}
post {
request.body.map { typedData ->
extractItem(typeData) // extract your item from the request first
}.flatMap { item ->
service.saveJsonAsItemLocation(item).promiseSingle() // then once it's extracted pass the item to your "saveJsonAsItemLocation" method
}.then { ItemLocationStore updatedItem ->
response.headers.add(HttpHeaderNames.LOCATION, "/itemloc/v1/save/${updatedItem.tcin}/${updatedItem.store}")
context.response.status(HttpResponseStatus.CREATED.code()).send()
}
}
}
}
My guess is that you have something like this:
get {
// get stuff
}
post {
// post stuff
}
The reason this doesn't work is that Ratpack doesn't use Routing Table for handling incoming requests, instead it uses chain delegation. The get {} binds to root path and GET http method and post {} binds to root path and POST http method. Because get {} matches the path, Ratpack considers the handler matched and since the handler is for GET it considers it a 405.
There are chain methods available that binds regardless of HTTP Method such as all {} and path {}. Chain#all will handle all paths and methods where as Chain#path(String) matches against specific path.
Hope this helps.
I am using &:extend(.klass)
I have a method:
.method(#mixin) {
html[something] & { #mixin() }
}
.klass {
.method({});
}
So far so good. However, when I use this:
.anotherclass { &:extend(.klass) }
I get no complaints, it extends the klass properly.
Resulting css:
html[something] .klass { ... }
.klass, .anotherclass { ... }
However, it should ideally, also extend the html[something] .klass as well.
So the result should IDEALLY be:
html[something] .klass, html[something] .anotherclass { ... }
.klass, .anotherclass { ... }
Right?
Otherwise, you could end up using &:extend(.klass) get no complaint, expecting to get the right rules applied.
I am using less on java, and it might be using an old version.
Does this work "better" in newer versions?
Note, I am aware I can just turn klass into a method call instead.
As we know that it is possible to intercept the state of the call using below code:
CTCallCenter *callCenter = [[CTCallCenter alloc] init];
callCenter.callEventHandler=^(CTCall* call)
{
if (call.callState == CTCallStateDisconnected)
{
NSLog(#"Call has been disconnected");
}
else if (call.callState == CTCallStateConnected)
{
NSLog(#"Call has just been connected");
}
else if(call.callState == CTCallStateConnected)
{
NSLog(#"Call is incoming");
}
else
{
NSLog(#"None of the conditions");
}
};
Can we intercept the dialled number by using Core Telephony framework.
Intercept a dialed number? If you are making the call, you already know the number right? If you meant intercept a received/incoming call and find its number, I don't think you can do that with CoreTelephony.
for all beginners... is ALWAYS better to read Apple API's docs, before.
This behaviour is stated clearly.