tkadauke / motion-resource Goto Github PK
View Code? Open in Web Editor NEWAccess RESTful resources from your iOS app. Inspired by ActiveResource.
Access RESTful resources from your iOS app. Inspired by ActiveResource.
I have the following classes:
class Market < MotionResource::Base
has_many :market_days
end
class MarketDay < MotionResource::Base
belongs_to :market
self.member_url = "markets/:market_id/market_days/:id"
end
And I'm trying to fetch a particular market_day through the market_days association:
market.market_days.find(day.date) do |market_day|
...
end
but this fails with:
undefined method `call' for "2013-06-16":String (NoMethodError)
from find.rb:61:in `request_block_call:'
from find.rb:18:in `block in fetch_member:'
from requests.rb:69:in `block in http_call:'
from query.rb:358:in `call_delegator_with_response'
("2013-06-16" is the ID of the date I'm trying to fetch).
Does motion-resource support this? Do I have the syntax wrong?
Hi,
Is there a way to add default headers to requests? e.g.
def self.headers
{
'Content-Type' => 'application/json',
'Authorization' => "Token token="#{App::Persistence['authToken']}""
}
end
class User < MotionResource::Base
attr_accessor :id
attribute :full_name, :abbreviated_name, :avatar50, :avatar70, :points_this_week, :points_today, :total_points, :monthly_points
has_many :hidukens
self.collection_url = "users"
self.member_url = "users/:id"
end
class Hiduken < MotionResource::Base
attr_accessor :id
attribute :user_id, :points, :multiplier
belongs_to :user
self.collection_url = "users/:user_id/hidukens"
self.member_url = "users/:user_id/hidukens/:id"
end
def my_load_data
User.find(app_delegate.user_id) do |my_user, response|
if response.ok?
my_user.hidukens do |h|
puts h.inspect
end
end
end
end
Makes a call to my api
/api/v1/users/:user_id/hidukens.json"
instead of
/api/v1/users/5/hidukens.json"
What would you think of using AFNetworking instead of bubble-wrap? It would add a dependency, but give much more flexibility
I have not set
app.detect_dependencies = false
the annoying this is i am using bundler so i think i would have to manually require all my libraries. Why is this the case?
Just a suggestion, I would include somewhere in the Readme the use of attribute
For example:
class Shape
attribute :color
end
It was a little confusing because I thought attr_accessor was the same as attribute.
Thanks!
In your examples, if I add collection_url to tag, I get an error.
Tag:
class Tag < MotionResource::Base
attr_accessor :name
belongs_to :color
collection_url "tags"
end
Error:
2013-03-16 11:11:32.905 Colr[62943:c07] *** Terminating app due to uncaught exception 'ArgumentError', reason: 'wrong number of arguments (1 for 0) (ArgumentError)
Hi @tkadauke
I'm having problems using your gem. I've everything set up, just like the readme tells me:
class Client < MotionResource::Base
MotionResource::Base.root_url = "http://localhost:3000/api/"
# Include the MotionModel
include MotionModel::Model
include MotionModel::ArrayModelAdapter
include MotionModel::Validatable
# Define the attribute accessors
attr_accessor :id
attribute :name
# Define the columns of this model
columns name: :string
# Validate the client model
validate :name, presence: true
# Define the URL's for this resource
self.collection_url = "client"
self.member_url = "client/:id"
end
But it seems there's no request send to the API. For your convenience my app_delegate.rb:
# app_delegate.rb
@client = Client.create( name: 'Your awesome client' )
p @client
Cheers!
In your examples, the Tag model inherits from "MotionResource::Base", however, in your readme is says "RemoteModule::RemoteModel"
This gem seems perfect, but how does it compare with https://github.com/sxross/MotionModel. Can I use both or are these mutually exclusive?
I'm getting the following error:
Terminating app due to uncaught exception 'ArgumentError', reason: 'base.rb:27:in `instantiate:': No :id parameter given for User.instantiate (ArgumentError)`
Here's the User
:
class User < MotionResource::Base
attr_accessor :id
self.collection_url = "users"
self.member_url = "users/:id"
self.default_url_options = {
:payload => {
'token' => "#{App::Persistence['facebook_access_token']}"
}
}
end
My JSON response looks like the following:
{
"success": true,
"user": {
"id": 13,
"name": "Josh Smith",
"email": "[email protected]",
"first_name": "Josh",
"last_name": "Smith"
}
}
Could this have something to do with not having the id
in the root object? Am I doing something else obviously wrong?
Thanks!
I'm trying to add motion-resource to my project, but it fails at runtime with:
*** Terminating app due to uncaught exception 'NoMethodError', reason: 'undefined method `class_attribute' for MotionResource::Base:Class (NoMethodError)
Should it work with RubyMotion 2?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.