Is there an example of using ActiveResource and XMLRPC for Rails?

I saw a lot of examples with ActionWebService and XMLRPC, but they are 3 years old and, as I understand it, ActiveResource should replace ActionWebService.

I am familiar with how ActiveResource can use XML to “communicate” with other websites and use model information, but XML-RPC is a completely different type in which you pass the name of the method you want to execute and the request is passed and so on. .d.

EDIT - I know how ActiveResource should work, but I have a client application that needs to use XML-RPC with a specific API (MetaWeblogAPI), and I have no choice but to implement it - my hands are tied.

So - in particular: I was trying to find some documents or write about how XML-RPC can be implemented using Rails using ActiveResource. Perhaps this cannot be - I would like to know that I am also engaged. I will just skip the “little jump” - “how do you pass the request to the method”, where I get to get the method name from the XML-RPC request and pass it to the method. I know that I'm thinking too much about it. Can't help - I'm a .NET guy :).

I tried to "use what works" - this means that I tried to implement ActionWebService, but it seems that it does not play well with Rails 2.3.5 (this is what I installed), as I continue to get the "Unknown constant" error indicating the installed ActionWebService (which makes me believe that Rails 2.x does not like).

n00b, :) - , , , , .

+3
2

, . XMLRPC Rails. Rails XML , XML, xml URL-, , XML-. :

def show
  @post = Post.find(:all, :conditions => { :id => params[:id] }
  respond_to do |format|
    format.html do
      # this is the default, this will be executed when requesting http://site.com/posts/1
    end
    format.xml do
      # this will be rendered when requesting http://site.com/posts/1.xml
      render :xml => @post
    end
  end
end

, XMLRPC, XML- URL-, Rails , XML.

ActiveResource, -

class Resource < ActiveResource::Base
  self.site = Settings.activeresource.site # 'http://localhost:3000/
  self.user = Settings.activeresource.username # Only needed if there is basic or digest authentication
  self.password = Settings.activeresource.password
end
class GenreResource < Resource
  self.element_name = 'genre'
end
class ArtistResource < Resource
  self.element_name = 'artist'
end
class AlbumResource < Resource
  self.element_name = 'album'
end)
class TrackResource < Resource
  self.element_name = 'track'
end
class AlbumshareResource < Resource
  self.element_name = 'albumshare'
end

, API, , TrackResource.exists?(34) track = TrackResource.new(:name => "Track Name"); track.save ..

ActiveResource. , ActiveResource , , Rails , XML , respond_to.

+2

/ ActiveResource , RESTful. XML-RPC.

-, XML-RPC ActiveResource .

LiveWriter ActiveResourceProxyService XML-RPC, ActiveResourceProxyService ActiveResource -.

, API , .

0

Source: https://habr.com/ru/post/1726679/


All Articles