Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8588999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:56:19+00:00 2026-06-11T22:56:19+00:00

I am trying to grab data from a third-party library that has an API

  • 0

I am trying to grab data from a third-party library that has an API that looks like:

https://foo.com/user.json?username=<USERNAME>

I can’t figure out how to force ActiveResource to use “user.json” instead of “users.json”. Is it possible?

I got it working with the reactive_resources gem … is there a way to do it in just pure ActiveResources?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:56:21+00:00Added an answer on June 11, 2026 at 10:56 pm
    class User < ActiveResource::Base
      self.element_name = "user"
    end
    

    Next, you are going to ask how to get one element from the URL which looks to ActiveResource to be //foo.com/user.json instead of //foo.com/user/.json

    User.find(:one, :from => "https://foo.com/user.json?username=#{<USERNAME>}"
    

    Edit in response to comment

    Is there a way to do this without having to enter the full URL of the request every single time I want to use find()?

    One way is to define a method in the class to do the full URL for you.

    class User < ActiveResource::Base
      self.element_name = "user"
    
      def self.find_by_username(username)
        find(:one, :from => "https://foo.com/user.json?username=#{username}"
      end
    
      def find
        self.class.find(:one, :from => "https://foo.com/user.json?username=#{username}"
      end
    end
    

    Another way is to redefine element_path.

    class User < ActiveResource::Base
      self.element_name = "user"
    
      def self.element_path(id, prefix_options = {}, options = {})
        "https://foo.com/user.json?username=#{prefix_options["user_id"]}"
      end
    end
    

    Some would call this monkey-patching, others would call it Object Oriented Programming. I say it’s only monkey-patching when you are going into the code or using Ruby’s dynamic nature to change the base behavior and this is a totally legitimate way to do things in Object Oriented Programming. However, the Ruby community doesn’t use OOP much, pretty much ignoring inheritance in favor of much looser (and less well behaved) mix-ins, and only using duck-typing for polymorphism.

    The issues with having to mess with ActiveResource to build an URL where you cannot redefine the web service to accept the ActiveResource conventions is why many are using HTTParty instead. “If you have to build the URL, might as well use HTTParty.“

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see that some people are trying to grab data from google spreadsheets via
i have a short script where i'm trying to grab data from a URL
I am trying to grab a row that has the max of some column.
I was trying to grab some data from the database using JQuery AJAx, and
I'm basically trying to get all touch event data from something like a system
I'm trying to grab data from a JSON on an external site but the
I am trying to grab some data from Delicious, using URL class, URL url
Im trying to grab all data(text) coming from a URL which is constantly sending
I'm trying to use Javascript to pull data from Yahoo Weather (eg http://weather.yahooapis.com/forecastrss?w=9807&u=c ).
I'm trying to grab data with a special character (caron) from a database and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.