That seems to work in regards to evaluating the response correctly, but I'm having trouble getting my data returned where it needs to go. I'll explain.
What I want to happen is I call a method that executes this code and returns the body (JSON).
I've extracted this code to a method in a class I created:
class Post
def self.index
temp_response = "hey hey"
BubbleWrap::HTTP.get(App::Persistence['app_url'].to_s + "/posts", {credentials: {username: App::Persistence['auth_token'], password: 'X'}}) do |response|
if response.ok?
temp_response = BubbleWrap::JSON.parse(response.body.to_str)
elsif response.status_code.to_s =~ /40\d/
App.alert("Login failed")
else
App.alert(response.ok?.to_s)
end
end
end
When Post.index is called, I get back "hey hey". I never get back the parsed JSON. Why?
Now if I instantiate an instance variable (@temp_response) in the view controller that calls Post.index, and then use that instance variable in place of the old 'temp_response', it works!
But that seems......messy.
Why is my local variable (temp_response) not taking the value I expect in the block?
What is the best way to do this?
Thanks!
-Johnny
On Monday, July 23, 2012 9:52:53 AM UTC-4, Christopher Brickley wrote:
Have you tried the block form?
BubbleWrap::HTTP.get(App::Persistence['app_url'].to_s + "/posts", {credentials: {username: App::Persistence['auth_token'], password: 'X'}}) do |response|
if response.ok?
App.alert("It's OK!")
elsif response.status_code.to_s =~ /40\d/
App.alert("Login failed")
else
App.alert(response.ok?.to_s)
end
On Mon, Jul 23, 2012 at 9:37 AM, Johnny Holton wrote:
I'm trying to retrieve some "posts" from my Rails app.
Here's my request:
response = BubbleWrap::HTTP.get(App::Persistence['app_url'].to_s + "/posts", {credentials: {username: App::Persistence['auth_token'], password: 'X'}}).response
if response.ok?
App.alert("It's OK!")
elsif response.status_code.to_s =~ /40\d/
App.alert("Login failed")
else
App.alert(response.ok?.to_s)
end
When I run the code, I get "false" from the last part of the if conditional
However, while the REPL is running, if I paste in the get request, then response.ok? is true and I can access the response like I expect to.
Why isn't it working in the app?
Thanks.
--
You received this message because you are subscribed to the Google Groups "BubbleWrap" group.
To post to this group, send email to bubbl...@googlegroups.com.