Sha256: 20894298e6bfa717d3bda874d95724502f8d3a7ebe4c65fe92f1e98c4f7c1e9b

Contents?: true

Size: 1.13 KB

Versions: 55

Compression:

Stored size: 1.13 KB

Contents

# *Flexirest:* Translating APIS (DEPRECATED)

**IMPORTANT: This functionality has been deprecated in favour of the [Proxying APIs](proxying-apis.md) functionality. You should aim to remove this from your code as soon as possible.**

Sometimes you may be working with an API that returns JSON in a less than ideal format. In this case you can define a barebones class and pass it to your model. The Translator class must have class methods that are passed the JSON object and should return an object in the correct format. It doesn't need to have a method unless it's going to translate that mapping though (so in the example below there's no list method). For example:

```ruby
class ArticleTranslator
  def self.all(object)
    ret = {}
    ret["first_name"] = object["name"]
    ret
  end
end

class Article < Flexirest::Base
  translator ArticleTranslator
  base_url "http://www.example.com"

  get :all, "/all", fake:"{\"name\":\"Billy\"}"
  get :list, "/list", fake:"[{\"name\":\"Billy\"}, {\"name\":\"John\"}]"
end

Article.all.first_name == "Billy"
```



-----

[< Proxying APIs](proxying-apis.md) | [Default parameters >](default-parameters.md)

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
flexirest-1.12.4 docs/translating-apis.md
flexirest-1.12.3 docs/translating-apis.md
flexirest-1.12.2 docs/translating-apis.md
flexirest-1.12.1 docs/translating-apis.md
flexirest-1.12.0 docs/translating-apis.md
flexirest-1.11.3 docs/translating-apis.md
flexirest-1.11.2 docs/translating-apis.md
flexirest-1.11.1 docs/translating-apis.md
flexirest-1.11.0 docs/translating-apis.md
flexirest-1.10.12 docs/translating-apis.md
flexirest-1.10.11 docs/translating-apis.md
flexirest-1.10.10 docs/translating-apis.md
flexirest-1.10.9 docs/translating-apis.md
flexirest-1.10.8 docs/translating-apis.md
flexirest-1.10.7 docs/translating-apis.md
flexirest-1.10.6 docs/translating-apis.md
flexirest-1.10.5 docs/translating-apis.md
flexirest-1.10.4 docs/translating-apis.md
flexirest-1.10.3 docs/translating-apis.md
flexirest-1.10.2 docs/translating-apis.md